Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm building a web app and I need a JS framework like Backbone.js to work with my backend provided by Rails that mostly return JSON objects after DB queries.

Searching on the web I've discovered Backbone which seems to be complete, quite popular and actively used in development but I've noticed that a lot of things done by Backbone are simply a duplicate of the work done by Rails: for example, validation and models.

My idea of "perfect" (for my actual needs) JS mvc (it can't be called mvc but I don't have a better name) is something really simple that has a function for each action in my Rails controller that is triggered by a specific event (user/hash changes, click on a button...) and sends requests to the server that respond with a JSON object then I'll load a template or execute some JS code.

Do you have any concerns about/suggestions for my idea?

Do you know of some "micro" js framework like what I have described?

If you have worked with backone.js + rails what can you suggest to me?

share|improve this question
2  
If you want something that hard coupled to rails you'll have to write it yourself. –  Raynos Mar 26 '12 at 14:57
add comment

3 Answers

Do you have any concerns about/suggestions for my idea?

The problem with your idea is that it couples your back end (Rails) with your font end (JavaScript). Also you say that validation on front end and back end is duplicating code, it is to some degree but you need to do it in both ends to make the site usable and safe. Validating front end helps usability where as validation server side is essential to stop hacks and make the site usable for those that turn JavaScript off.

Do you know of some "micro" js framework like what I have described?

There are lots of Javascript MVC/MVVC frameworks out there like backbone and knockout but they are decoupled. This means they are more portable, more usefull and more likely to be worked on and improved.

share|improve this answer
add comment

I don't have any concerns about your idea, apart from what prashanth already mentioned. I'd make sure there is some validation on the server side, just in case somebody skips your JS front-end and starts pumping invalid data straight into your JSON API.

As a suggestion, I'd check out TodoMVC. They've written a TODO application using a number of JavaScript framworks for implementing client-side MVC (including Backbone.js). They've done a lot of the hard work in highlighting the differences for you.

microjs is another site I'd check out. I found both soma.js and Stapes.js (really small at 1.7Kb) there.

I haven't worked with any of these frameworks personally, but I know devs using backbone and ember. Ember seems to be gaining in popularity as it matures. It seems to be a little more opinionated than backbone is, which I suspect resonates with a lot of rails developers.

share|improve this answer
add comment

You should always do validation on the server. Backbone validations are optional. they are there to improve usability of the app.

share|improve this answer
1  
Your answer would be more helpful if you provided more about how this relates to the three bolded questions. I'm guessing you are listing concerns, but this might not immediately be clear if the original poster isn't a native English speaker. –  Jennifer S Jun 20 '12 at 17:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.