问题
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