Installing jQuery in Rails 3.2.13

后端 未结 2 585
长情又很酷
长情又很酷 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

    0 讨论(0)
  • 2021-01-22 22:38

    Check your browser's console for any load error. It seems that you are not deploying the javascript, so it's not loaded.

    Either use

     <%= javascript_include_tag "//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" %>
    

    or have a copy of the file you are serving in any of

    /lib/assets/javascripts
    /vendor/assets/javascripts
    /app/assets/javascripts
    
    0 讨论(0)
提交回复
热议问题