[英]How can I use Jquery in rails 3.2.8?
All the tutorials I've read tell me to use the "public/javascripts" folder. 我读过的所有教程都告诉我使用“public / javascripts”文件夹。 But there is no such folder in rails 3.2.8 但是在rails 3.2.8中没有这样的文件夹
The default Rails application (> 3.2) includes the jQuery gem on line 23 of the Gemfile: 默认的Rails应用程序(> 3.2)包含Gemfile第23行的jQuery gem:
gem 'jquery-rails'
You place your jQuery code in a custom JavaScript file--eg, hello.js
--in the following path: 您将jQuery代码放在自定义JavaScript文件中 - 例如, hello.js
- 在以下路径中:
app/assets/javascripts/
Example: 例:
app/assets/javascripts/hello.js
In hello.js
, make sure you include your jQuery code inside of this block: 在hello.js
,确保在此块中包含jQuery代码:
$(document).ready(function() {
YOUR CODE HERE
});
That's it. 而已。 You're ready to use jQuery in Rails. 你已经准备好在Rails中使用jQuery了。 (This works because of line 15 in app/assets/javascripts/application.js
) (这是因为app/assets/javascripts/application.js
的第15行)
//= require_tree .
This line says to include everything in the javascripts
directory. 该行说明包含javascripts
目录中的所有内容。
You need the gem. 你需要宝石。 Maybe this will help you: 也许这会对你有所帮助:
http://c.kat.pe/post/how-to-use-jquery-for-rails-3/ http://c.kat.pe/post/how-to-use-jquery-for-rails-3/
You can write a jquery code and put file as file_name.js in Javascript folder and call this file in your layout file. 您可以编写jquery代码并将文件作为file_name.js放在Javascript文件夹中,并在布局文件中调用此文件。 You can refer http://jqueryui.com/ 你可以参考http://jqueryui.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.