新图像未在 Rails 3.1 中呈现 [英] New Image not Rendering in Rails 3.1
问题描述
我刚刚在我的网站 assets/images/loading.gif 中添加了一个新的加载轮.gif 在开发中确实有效,但在生产中,浏览器会呈现一个损坏的图像图标,没有错误.服务器将文件显示为 0 字节,但是当我在终端中找到该文件时,我可以看到它是 3.2k.来自资产/图像的其他图像确实有效.搜索后,我尝试了几件事,包括预编译和更改配置中的行,但到目前为止,都没有奏效.是权限问题还是缓存问题?
I have just added a new loading wheel to my site in assets/images/loading.gif. The gif does work in development, but in production, the browser renders a broken image icon, with no errors. The server is showing the file as 0 bytes, but when I locate the file in the terminal, I can see that it is 3.2k. Other images from assets/images do work. After searching, I tried several things including precompile and changing lines in my config, but as yet, none have worked. Could it be a permissions or a caching issue?
已解决:
该问题是引用问题.我最初是在直接的 html 中引用 gif,就像这样......
The issue was a referencing issue. I was initially referencing the gif in straight html, like so...
<img src="assets/loading.gif" id="loading-indicator" style="display:none" />
但是当我使用 image_tag 并更改文件路径时,它现在可以工作了.
but when I used image_tag and changed the file path, it now works.
<%= image_tag("loading.gif", :id => "loading-indicator", :style => "display:none") %>
不知道为什么它最初在我的本地工作.
Not sure why it worked on my local initially.
推荐答案
在 Heroku 上升级到 Cedar 后,我也遇到了同样的问题,所以我猜您正在使用 Heroku 在 Cedar 上托管您的 Rails 3.1 应用程序.
This same issue happened to me after I upgraded to Cedar on Heroku, so I'm guessing you're using Heroku to host your Rails 3.1 app on Cedar.
如果是这样,请在您的 config/environments/production.rb 文件中尝试此操作,注释掉以下行:
If so try this in your config/environments/production.rb file comment out the following line:
config/environments/production.rb
===================================
...
config.action_dispatch.x_sendfile_header = "X-Sendfile"
...
并用这个新行替换它:
config/environments/production.rb
===================================
...
config.action_dispatch.x_sendfile_header = nil # For Heroku
...
这篇关于新图像未在 Rails 3.1 中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!