Update: Since this article was written, the jquery-ujs project has been turned into a gem which includes a generator that streamlines this process. Instructions can be found in the README for the Github project.
you’ll now see it written as
So, enough blabbing. How do you get jQuery working with Rails 3? I’ll try to make this short and sweet.
Include jQuery (I just use the google hosted version) and the driver in your application layout or view. In HAML it would look something like.
Rails requires an authenticity token to do form posts back to the server. This helps protect your site against CSRF attacks. In order to handle this requirement the driver looks for two meta tags that must be defined in your page’s head. This would look like:
In HAML this would be:
Update: Jeremy Kemper points out that the above meta tags can written out with a single call to “csrf_meta_tag”.
That should be all you need. Remember, this is still a work in progress, so don’t be surprised if there’s a few bugs. Please also note this has been tested with Rails 3.0.0.beta.