【问题标题】:New Image not Rendering in Rails 3.1Rails 3.1 中未呈现新图像
【发布时间】:2012-03-31 14:53:01
【问题描述】:

我刚刚在 assets/images/loading.gif 中为我的网站添加了一个新的加载轮。 gif 确实在开发中工作,但在生产中,浏览器呈现一个损坏的图像图标,没有错误。服务器将文件显示为 0 字节,但是当我在终端中找到该文件时,我可以看到它是 3.2k。资产/图像中的其他图像确实有效。搜索后,我尝试了几件事,包括预编译和更改配置中的行,但到目前为止,都没有奏效。可能是权限问题还是缓存问题?

已解决:

这个问题是一个引用问题。我最初是在直接 html 中引用 gif,就像这样......

<img src="assets/loading.gif" id="loading-indicator" style="display:none" />

但是当我使用 image_tag 并更改文件路径时,它现在可以工作了。

<%= image_tag("loading.gif", :id => "loading-indicator", :style => "display:none") %>

不知道为什么它最初在我的本地工作。

【问题讨论】:

  • 你是如何在代码中引用图片的?

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1


【解决方案1】:

我在 Heroku 上升级到 Cedar 后也发生了同样的问题,所以我猜您正在使用 Heroku 在 Cedar 上托管 Rails 3.1 应用程序。

如果是这样,请在您的 config/environments/production.rb 文件中将以下行注释掉:

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
...

【讨论】:

    猜你喜欢
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多