微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rails 3.1 + Heroku Cedar-未提供静态图片资源

如何解决Rails 3.1 + Heroku Cedar-未提供静态图片资源

|| 我已经在Heroku Cedar上部署了Rails 3.1应用程序。由于某些原因,我的静态图片资产未投放:
2011-06-23T18:14:13+00:00 app[web.1]: Started GET \"/assets/me_reminder-30f9d1dead32e12238888adbee4b92d3.png\" for 98.207.60.248 at 2011-06-23 18:14:13 +0000
2011-06-23T18:14:13+00:00 app[web.1]: Served asset /me_reminder-30f9d1dead32e12238888adbee4b92d3.png - 200 OK (0ms) (pid 1)
2011-06-23T18:14:13+00:00 app[web.1]: cache: [GET /assets/me_reminder-30f9d1dead32e12238888adbee4b92d3.png] miss,store
2011-06-23T18:14:13+00:00 heroku[router]: GET xxxx.herokuapp.com/assets/me_reminder-30f9d1dead32e12238888adbee4b92d3.png dyno=web.1 queue=0 wait=0ms service=35ms status=200 bytes=0
如您所见,它返回的内容为0字节。不用说,没有图像显示。 但是,我所有其他静态资产(css,javascript)均已正确投放。知道这里有什么问题吗? 顺便说一句,我在heroku上有另一个Rails 3.1应用程序,它运行正常,所以我认为链轮等不是问题。 谢谢。     

解决方法

        我有同样的问题。在
config/environments/production.rb
文件中,评论:
config.action_dispatch.x_sendfile_header = \"X-Sendfile\"
相反,有:
config.action_dispatch.x_sendfile_header = nil # For Heroku
这也是推荐的方法。如Heroku文档中所建议。 为我工作。     ,        我有同样的问题。将production.rb文件配置更改为
config.action_dispatch.x_sendfile_header = \'X-Accel-Redirect\'
config.action_dispatch.x_sendfile_header = \"X-Sendfile\"
为我工作。因为Heroku在前面使用了nginx。     ,        我遇到了这个问题,因为我是在使用HTML引用资产管道中的图像。例:
<img src=\"/assets/hello.jpg\" />
图像资产将在本地运行,但不能在Heroku上运行。切换到使用Rails的
image_tag
视图助手可以解决此问题。例:
<%= image_tag \"hello.jpg\" %>
    ,        如果我没记错的话,在资产管道中使用图片可能会出现一些意外情况。为避免这种情况,您可以像以前版本的滑轨一样将它们留在ѭ9中。 请参阅此处的讨论。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。