Rails 4.2: image path and fingerprint are only added when config.assets.compile = true

During production, the correct paths to my images are not called with the image tag, and the md5 fingerprint is not added. Image names (for example, "pretty_picture.jpg") are stored in the database. Precompilation files are present in the shared folder, including the manifest file.

When called using image_tag:

image_tag @test_question.question.image 

I get:

 <img src="/images/pretty_picture.jpg"> 

If I set config.assets.compile = true in production.rb, the image is displayed and I get:

 <img src="/assets/images/pics/pretty/pretty_picture-e0df5012b6930cda4efaa866af22a63f.jpg" > 

My hacking solution is to use (in HAML)

 %img{src: "/assets/"+Rails.application.assets.find_asset(@test_question.question.image).digest_path} 

In production.rb I have

 config.assets.digest = true config.assets.enabled = true config.serve_static_files = false config.assets.compile = false 

Setting config.assets.compile to true during production is not recommended. This seems like a very strange behavior on behalf of asterisks and an asset pipeline. Any idea what is wrong with using image_tag here?

+5
source share
1 answer

During production, you must pre-assemble the assets before starting the server with the following command (and automate it to do this every time you deploy):

 rake assets:precompile RAILS_ENV="production" 

and save config.assets.compile = false in production.rb . Go to the Piping Network Guide .

+1
source

All Articles