[英]How to make controller/view specific Javascript work in a Rails 3.1 production environment
我试图在Rails 3.1中创建视图/控制器特定的Javascript。 我遵循了Rails 3.1资产管道中的方法:如何加载控制器特定的脚本? 和http://tech.thereq.com/post/10754558724/the-rails-3-1-asset-pipeline-in-the-real-world-jquery 。
这在我的开发环境中效果很好。 但是,它在我的生产环境中失败。 我收到消息ActionView :: Template :: Error(未预编译users.js)。
我在... / app / assets / javascript目录中的user.js.coffee文件包含
//= require i18n/grid.locale-en
//= require jquery.jqGrid.min
//
//= require grid_object.js
我在... / app / views / users中的index.html.haml文件包含
- javascript 'users'
...
我的application_helper包含
def javascript(*files)
content_for(:head) { javascript_include_tag(*files) }
end
我的应用程序布局文件包含
%= yield(:head) %>
最后,我在... / app / assets / javascript中的application.js文件包含
//= require jquery
//= require jquery-ui
我想念什么?
我决定为需要预先编译的所有控制器/视图特定的javascript使用后缀(即“ _pc”)。 所需的更改是:
在我看来,我使用了:
- javascript require 'users_pc'
我将users.js.coffee文件重命名为users_pc.js.coffee
最后,我将我的... / config / environments / production.rb文件更新为包含
- config.assets.precompile << '*_pc.js'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.