Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install jQuery on rails 3.1

I assumed it was already installed but in my gemfile i have

gem "jquery-rails"

but in the asset/javascripts folder i have

accounts.js.coffee
application.js

which are both commented out

Here is my dummy rails application but in the source there is no jQuery and the delete link doesnt work...any ideas whats missing

like image 895
Matt Elhotiby Avatar asked Aug 23 '11 21:08

Matt Elhotiby


2 Answers

Have a look at this Railscast. You might want to check the application.js file and make sure it contains the following statement.

//= require jquery
//= require jquery_ujs
like image 192
Simone Carletti Avatar answered Sep 25 '22 15:09

Simone Carletti


Besides adding query-urj in you Gemfile, you also need to run this to generate jquery.js and query_ujs.js:

rails generate jquery:install

This will install jquery.js for you.

As for the 'commented out' application.js, if it has these lines:

//= require jquery
//= require jquery_ujs

Then you're ready to go. They are not just comments, they actually tell the pipeline to use jquery and jquery_urj. When you app runs, both js files will be merged into application.js.

like image 37
James Chen Avatar answered Sep 22 '22 15:09

James Chen