New Image not Rendering in Rails 3.1

青春壹個敷衍的年華 提交于 2021-01-28 09:06:31

问题


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?

Solved:

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" />

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.


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

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

And replace it with this new line:

config/environments/production.rb
===================================
...
config.action_dispatch.x_sendfile_header = nil # For Heroku
...


来源:https://stackoverflow.com/questions/9909030/new-image-not-rendering-in-rails-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!