Heroku/Thin 上未提供静态资源
我遇到了 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"):
我正在使用:
- Ruby 1.9.2
- Rails 3.0.7
- Heroku 与bamboo-mri-1.9.2 和瘦网络服务器。 (我按照 heroku.com 上的默认基本设置说明进行操作)
我在 google / stackoverflow 上进行了搜索,并尝试了以下操作,但没有成功:
- remove config.ru
- add
use ActionDispatch::Static, "#{Rails.root}/ public”
到 config.ru - 在 staging.rb 中设置
config.serve_static_assets = true
任何人都可以建议修复吗?我应该使用雪松而不是竹子吗?我应该使用其他东西来代替薄吗?
谢谢!
编辑: 正在提供 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
I'm having trouble with static assets (images and js and stylesheets) not being served on Heroku.
Works fine in my local dev env.
Errors look like this:
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"):
I'm using:
- Ruby 1.9.2
- Rails 3.0.7
- Heroku with bamboo-mri-1.9.2 and thin webserver. (I followed default basic setup instructions on heroku.com)
I've searched on google / stackoverflow and tried the following with no luck:
- remove config.ru
- add
use ActionDispatch::Static, "#{Rails.root}/public"
to config.ru - set
config.serve_static_assets = true
in staging.rb
Can anyone suggest a fix? Should I be using Cedar instead of Bamboo? Should I be using something else instead of thin?
Thanks!
EDIT:
js files are being served, but images and stylesheets are not.
I checked that the paths in my links are consistent.
myapp.heroku.com/stylesheets/reset.css
- failsmyapp.heroku.com/javascripts/jquery.js
- succeeds
I also attempted to set the following: config.action_dispatch.x_sendfile_header = nil
.
This goes along with config.serve_static_assets = true
but noticed that Heroku forces these options no matter how you set them. i.e. it does the following during startup:
-----> 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题结果是资产文件没有被推送到heroku(我遇到了git搞砸了,而不是heroku问题)。
当我联系 Heroku 支持人员时,他们指出了这一点。他们很快回复了详细的答案,其中还包括以下评论:
The problem turned out to be that the asset files didn't get pushed to heroku (I had a git screwup, not a heroku issue).
Heroku support pointed this out when I contacted them. They promptly replied with a detailed answer, which also included the following comments:
我不确定 Heroku 是否在
staging
环境中运行,我认为它是在生产
环境中运行,这就是您的设置未被应用的原因。I am not confident that Heroku is running in the
staging
environment, I think it's running in theproduction
environment instead and this is why your settings are not being applied.