我在Heroku上没有提供静态资产(图像和js和样式表)时遇到问题。 在我的本地开发环境中正常工作。
错误看起来像这样:
2011-08-08T02:58:45+00:00 app[web.1]: Started GET "/stylesheets/reset.css" for 98.234.235.21 at 2011-08-07 19:58:45 -0700
2011-08-08T02:58:45+00:00 app[web.1]:
2011-08-08T02:58:45+00:00 app[web.1]: ActionController::RoutingError (No route matches "/stylesheets/reset.css"):
我正在使用:
我在google / stackoverflow上进行了搜索并尝试了以下操作但没有运气:
use ActionDispatch::Static, "#{Rails.root}/public"
添加到config.ru config.serve_static_assets = true
有人可以建议修复吗?我应该使用Cedar而不是Bamboo吗?我应该使用其他东西而不是瘦吗?
谢谢!
修改 正在提供js文件,但图像和样式表不是。 我检查了链接中的路径是否一致。
myapp.heroku.com/stylesheets/reset.css
- 失败
myapp.heroku.com/javascripts/jquery.js
- 成功
我还尝试设置以下内容:config.action_dispatch.x_sendfile_header = nil
。
这与config.serve_static_assets = true
同时发生,但注意到无论你如何设置它们,Heroku都会强制执行这些选项。即在启动期间执行以下操作:
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
Installing rails3_disable_x_sendfile... done
答案 0 :(得分:3)
问题原来是资产文件没有被推送到heroku(我有一个git screwup,而不是heroku问题)。
当我联系他们时,Heroku的支持指出了这一点。他们立即回复了详细的答复,其中还包括以下评论:
答案 1 :(得分:0)
我不相信Heroku在staging
环境中运行,我认为它正在production
环境中运行,这就是为什么你的设置没有被应用。