Add jQuery to Ruby on Rails

by Buddy Lindsey on October 14, 2010

In a previous post I talked about using jQuery and modifying the rails.js file to fit your needs doing deletion. Recently I figured out a much better way to do this. You can install a gem then run a rails generate command which will delete your current javascript files and replace them with the appropriate jQuery files.

Step 1: Install “jquery-rails” Gem

In command line type:

gem install jquery-rails

Or Add the following line to your gemfile project and run the “bundle install” command

gem ‘jquery-rails’

Step 2: Add jQuery to Project

Open up your project in command line and type:

rails generate jquery:install

If you want to use jQuery UI add –ui

rails generate jquery:install –ui

That is it. Fairly simple to do for more information about this gem visit the githup repo for it. jquery-ujs github repositor. I recommend adding the line to your gem file for doing the install. However, if you want to add jquery manually visit the github page for manual installation instructions.

Related Posts:

Was this Helpful?

If you found this article useful you might find others useful as well. Please browse the archives and subscribe to the RSS Feed to stay up-to-date.

ashish October 28, 2010 at 9:48 am

Which version of Rails is this installation for?

Reply

Buddy Lindsey October 28, 2010 at 10:27 am

Rails 3 is what I used it on. However, I have found you can pick and pull things out as needed if it doesn’t work quite right. I don’t know if it works for rails 2.*

Reply

Leave a Comment

Previous post:

Next post: