Ruby-on-rails – Backbone.js frontend with RESTful Rails backend

backbone.jsfrontendmodel-view-controllerruby-on-rails

I started in the web development world with PHP, and then Rails in the recent few years. Since then I've been doing all my web projects in Rails.

Recently there seems to be a movement towards making Rails as a pure RESTful backend service and using frontend framework such as Backbone.js for all frontend interaction. I'm wondering what's you guys' take on it? Will this be the eventual future?

As well, besides Backbone.js, what are some other alternatives for frontend framework for this purpose?

Also assuming that I will want to support both a desktop version and a mobile version of my app, would this be a proper route to take? So I'll have a single backend service with different frontend services? This way I don't need to manage all the views on Rails' side?

Thanks!

Best Answer

For Client-side frameworks, this article has a list of 20 of them with pro's and con's: http://net.tutsplus.com/articles/web-roundups/20-javascript-frameworks-worth-checking-out/

Here's the list:

  1. Backbone.js
  2. Knockout.js
  3. Asana luna
  4. Cappucino
  5. Sproutcore
  6. BatmanJS
  7. corMVC
  8. TrimJunction
  9. pureMVC
  10. jamal
  11. choco
  12. sammyjs
  13. extJS
  14. agilityJS
  15. eyeballs
  16. activejs
  17. spinejs
  18. qooxdoo

These are roughly all about creating client-side, ajax-based, javascript MVC frameworks.

If you're looking to start somewhere, then I recommend thinking about Client-Side Templates (...ates...ates...ates) (just the "V") to support a service-oriented architecture (many clients are supported by service-endpoints you create).

It's a new technique that involves modularizing your client-side code, bringing MVC to the client, and let business-logic live in the platform. A lot of Software-as-a-Service applications are leveraging them, and with the increasing sophisticated of javascript libraries and frameworks, as well as browser capabilities with HTML5, CSS3, etc. there's going to be an increasing sophistication in client-side presentation.

So learn it.

What are the benefits?

To paraphrase Linked In: for leveraging browser-caching, de-coupling your front-end client-side presentation, asynchronous load, progressive rendering (for some frameworks), performance, ajax-interaction, and more.

Several great frameworks include:

  1. mustache
  2. dust.js
  3. handlebars
  4. Google Closure Templates
  5. Nun
  6. Mu
  7. kite

I highly recommend looking at Linked In's move away from JSP towards Client-Side Templates and why they choose dust.js in Linked In's front-end client-side templates throwdown for a comparison. They go into much greater detail, and research, as to why they changed their stack to support this (it involved using 3 server-side technologies), as well as their comparisons of all the frameworks they could find.