在Rails中安装jQuery 3.2.13

我无法让jQuery在Ruby on Rails 3.2.13上工作。 我查看了教程,搜索了youtube等等,但仍然无法让它工作。

更具体地说,我在使用jQuery ui时遇到了麻烦。 我无法让手风琴小部件工作。 我甚至无法获得简单的jQuery(如显示hello警告消息)来处理ROR。

非常感谢您的帮助。 谢谢!

这是我的application.html.erb文件:

   TestProj  "all" %>        

这是我的gem文件:

 source 'https://rubygems.org' gem 'rails', '3.2.13' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' # To use Jbuilder templates for JSON # gem 'jbuilder' # Use unicorn as the app server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger # gem 'debugger' 

她是我的application.js文件:

 // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require_tree . $(document).ready(function() { alert('Thanks for visiting!'); }); 

Jquery在Rails 3.2.13中自动化,请参阅你的Gemfile,如果你的Gemfile上有gem’jquery gem 'jquery-rails' ,你应该使用'application' ,不带'jquery-1.10.1.js' ,jquery-rails最新版本使用jQuery 1.10.1 请看这里

 <%= javascript_include_tag :application %> 

这将加载app/assets/javascript/application.js文件以加载app/assets/javascript文件夹中的所有其他javascript文件,包括jQuery:

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

如果你想使用JQuery UI,你可以使用jquery-ui-rails gem https://github.com/joliss/jquery-ui-rails

在您的Gemfile中,添加:

gem 'jquery-ui-rails'

并运行bundle install

请阅读此处以供使用

检查浏览器的控制台是否有任何加载错误。 看来你没有部署javascript,所以它没有被加载。

要么使用

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

或者拥有您正在服务的文件的副本

 /lib/assets/javascripts /vendor/assets/javascripts /app/assets/javascripts