Installing jQuery in Rails 3.2.13

后端 未结 2 588
长情又很酷
长情又很酷 2021-01-22 21:47

I am having trouble getting jQuery to work on Ruby on Rails 3.2.13. I have looked at tutorials, searched youtube, etc. and I still can\'t get it to work.

More specifica

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 22:33

    Jquery automate in Rails 3.2.13, see on your Gemfile, if you have gem 'jquery-rails' on your Gemfile, you should be using 'application', without 'jquery-1.10.1.js', jquery-rails latest version using jQuery 1.10.1 see here

    <%= javascript_include_tag :application %>
    

    This will load the app/assets/javascript/application.js file to load all your other javascript files on app/assets/javascript folder, including jQuery:

    //= require jquery
    //= require jquery_ujs
    //= require_tree .
    
    $(document).ready(function() {
     alert('Thanks for visiting!');
    });
    

    If you want use JQuery UI, you could use jquery-ui-rails gem https://github.com/joliss/jquery-ui-rails

    In your Gemfile, add:

    gem 'jquery-ui-rails'

    and run bundle install

    read here for usage

提交回复
热议问题