My apologies for dropping off the face of the earth. I've been working hard at Procore, which I mentioned last time, and getting neck-deep in the specific problems that make working with jQuery and Rails at the same time so difficult.
Since I last publicly discussed jQuery on Rails, I've gone down a lot of avenues, and written a lot of code, and came to some conclusions:
- The biggest problem faced by jQuery developers is not simplicity (which, again, you get for free in the library), but difficulty in including the correct jQuery "modules" in the Rails views that require them.
The most common problem with using jQuery with Rails in an app of moderate or higher complexity is the trade-off between including everything in a single
application.js (which can lead to serious slowdowns in larger apps) and having multiple, modular files (which are a serious pain to include correctly as needed).
This is a problem for jQuery users who want to use Rails more than Rails users who are used to Prototype helpers and want to be able to use the jQuery library as a drop-in replacement. In the first release of jQuery on Rails, I will be targeting jQuery developers who want to work with Rails. In other words, jQuery on Rails is for you if you know jQuery or are willing to use jQuery.
With all that said, what does jQuery on Rails actually do?
First up, it's a Rails plugin, which you activate by adding
<%= include_jquery %> in your
include_jquery is called in your layout, it'll get the rendered HTML and use Hpricot (which shares syntax with jQuery) to determine whether any instances of the selectors identified on server startup are present.
So in short:
include_jqueryin your layout
- You're done
I'll be demoing the code at RailsConf tonight and should be releasing the first beta version sometime in the next week. If you're at RailsConf, check out the Birds of a Feather presentation at Room c122 at 9:30 pm tonight.