开发者

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


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


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.


As far as I guess, jquery is not located at app/assets, but vendor/assets.

app/assets refers to your assets you need for this particular app.

lib/assets is for assets you share across multiple applications.

vendor/assets is for assets not maintained by you, like jquery.


JQuery is the default in rails 3.1. It comes from the jquery-rails gem.

The comments in application.js are actually used by the asset pipeline to combine your assets and serve them as a single file.

http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/


Just download a copy of jQuery from here :http://code.jquery.com/jquery-1.6.2.js

Then copy the file jquery-1.6.2.js into your folder <>/public/javascripts.

Then, in your application.html.erb file in your layout, include the jquery file before you include the application.js file, as shown below:

<%= javascript_include_tag 'jquery-1.6.2', 'application' %>

Then you are good to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜