问题:
如何让 Assets 管道处理所有您的 .js 文件?(我希望它们单独提供,而不是捆绑到 application.js 中)
我的页面试图引用的 javascript 文件收到大量 404:
GET http://<myStagingServer>.heroku.com/assets/<javascriptFilename1_MD5fingerprint> 404 (Not Found)
GET http://<myStagingServer>.heroku.com/assets/<SubDir>/<javascriptFilename2_MD5fingerprint> 404 (Not Found)
我尝试将此添加到 config/application.rb
:
config.assets.precompile << '*.js'
但据我所知,这并没有起到任何作用。
背景:
我正在从 Rails 3.0 升级到 3.1 并启用 Assets 管道。
迄今为止的亮点:
- 从 Bamboo 切换到 Heroku 的 Cedar 堆栈:
heroku create --stack cedar
。 - 切换到“瘦”作为生产服务器,解决了各种问题:
gem 'thin'
。 - 将我的 Assets 从
public/assets
移动到app/assets
,更新代码中的引用以使用stylesheet_link_tag
和javascript_include_tag
。 (加上我为图像所做的一切——它们起作用了。) - 删除 x_sendfile_header 配置选项,因为 Heroku doesn't support it .
相关文件:
//
// application.js
//
//= require_self
//
最佳答案
我的天啊:我发现了问题:
名称中带有句点的 javascript 和样式表需要显式扩展
例如:
# WORKS
javascript_include_tag "application"
stylesheet_link_tag "application"
# BROKEN
javascript_include_tag "jueryui.custom"
stylesheet_link_tag "jueryui.custom"
# WORKS
javascript_include_tag "jueryui.custom.js"
stylesheet_link_tag "jueryui.custom.css"
我想我明白为什么会这样,但我认为在任何 Assets 管道教程中都没有很好地记录它。 Assets 文件名中不应包含句点是常识吗?
关于ruby-on-rails - Assets :precompile for . js 文件? rails 3.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9346460/