简体   繁体   中英

Rails 3.1.x - image_tag doesn't use the precompiled file in production mode

In my views I put :

<%= image_tag("coin.png") %>

My original image is put on :

app/assets/images/coin.png

But in production mode the html code generated by image_tag is :

<img alt="Coin" src="/assets/coin.png">

Instead of hitting precompiled assets :

coin-aba0e66819d64251cb3bb4bb29b26eb2.png

(and naturally I cant see the image).

I didn't forgot to precompile my assets.

and my environment/production.rb is :

  config.cache_classes = true                                                                                                                                                                                   
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true                                                                                                                                                               
  config.serve_static_assets = false                                                                                                                                                                                                              
  config.assets.compress = true                                                                                                                                                                                                
  config.assets.js_compressor  = :uglifier
  config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"   

Thanks you a lot

I found it !!!!!!!

Add to your production.rb :

config.assets.digest = true

As stated in the latest part of this railscasts Rails 3.1 won't use ?hash cache expiring anymore. It will use an hash in the filename itself for assets. Don't know if for images is the same (haven't played with 3.1 yet), but it could be your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM