我阅读的所有教程都告诉我使用"public/javascripts"文件夹.但是在Rails 3.2.8中没有这样的文件夹
All the tutorials I've read tell me to use the "public/javascripts" folder. But there is no such folder in rails 3.2.8
- 我在哪里放置我的jquery代码?
- Rails 3.2.8中不包含Jquery吗?
默认的Rails应用程序(> 3.2)在Gemfile的第23行包含jQuery gem:
The default Rails application (> 3.2) includes the jQuery gem on line 23 of the Gemfile:
gem 'jquery-rails'您将jQuery代码放在自定义JavaScript文件(例如hello.js)中的以下路径中:
You place your jQuery code in a custom JavaScript file--e.g., hello.js--in the following path:
app/assets/javascripts/示例:
app/assets/javascripts/hello.js在hello.js中,确保在此块中包含jQuery代码:
In hello.js, make sure you include your jQuery code inside of this block:
$(document).ready(function() { YOUR CODE HERE });就是这样.您已经准备在Rails中使用jQuery. (由于app/assets/javascripts/application.js中的第15行,因此可以正常工作)
That's it. You're ready to use jQuery in Rails. (This works because of line 15 in app/assets/javascripts/application.js)
//= require_tree .此行说要包括javascripts目录中的所有内容.
This line says to include everything in the javascripts directory.
更多推荐
如何在Rails 3.2.8中使用Jquery?
发布评论