There are a lot of different ways to use javascript in rails 3.0. I was wondering what would be the best approach for a very complex ajax application.
It seems that the more progressive programmers are using coffee script these days, and I don’t mind learning something a little new.
I have already removed prototype and swapped it for jquery-rails.
Still, I’m not sure if this is enough. I reallyed like require-js, because it really helps modularize code and split everything up into different files. But does this work well with rails’ approach?
Also, I may want to use a javascript application framework like backbone. Again, is this overkill or will everything work?
What is the best stack to make very complex ajax applications in rails 3.0.7? What is easiest to develop with and is a nice fit for how rails works?
These decisions are pretty important to make early on, and I don’t want to be re-doing my javascript over and over until I get it right. I’d like to draw on the experience of those who’ve built really complex ajax apps using rails. Thanks!
This depends on how godly you are at not writing organically growing spaghetti code with your jQuery code everywhere.
An alternative approach is to keep your JavaScript completely separate from your rails.
You just need one entry point in a view somewhere
script(type="text/javascript" src="require/require.js" data-main="main.js")I personally recommend you treat
main.jsas a boot-strapper.Now you can do all your JavaScript through your main javascript library including loading anything you care about.
ender, Backbone, underscore, extJS (for the UI), whatever you want.
This does mean you JavaScript is very separate from your rails server, but that’s ok because you do all your communication over ajax using well defined web APIS.
If your complex ajax application needs to be real time you might want to look at comet or websockets.