Reputation: 319
For some reason when I tried to update my websites logo the image does not appear when I push it to Heroku, just the images' file name as a link. The images appear fine locally. I have png files saved in the images folder under my assets, so its not an issue of Heroku not finding it. I saw a post similar to this, but it really didn't answer my question. So why is the new image not appearing?
Upvotes: 2
Views: 1976
Reputation: 666
This is my experience: [ruby 2.30, rails 4.2.6]
following heroku instruction asset pipeline on rails 4
in config/application.rb add setting below
config.serve_static_assets = true # deprecated
use instead
config.serve_static_files = true # Ok
in Gemfile add
gem 'rails_12factor', group: :production
then, as heroku says, set ruby version in your Gemfile
gem ruby '2.3.0'
Now you can update your dependencies running
bundle install
Then you should adapt your source code:
changing image_tag "source_name" everywhere it appears without extension
<link_to image_tag("icon") ... %>
with image_tag "source_name" with extensions (.png, .jpg or whatever)
<link_to image_tag("icon.png") ...%>
You shouldn't run
RAILS_ENV=production rake assets:precompile
because heroku does this for you during deploy.
...and now is time to deploy
git add <files modified>
git commit -m "comments your commit"
git push heroku <your branch>
This solved for me ... I hope also for you.
Upvotes: 2
Reputation: 161
Add this to show precompiled image. On heroku default mode is production.So it need to display precompiled images. When an image or assets are precompiled. It compresses the code and image gets renamed to for example:(image_42342j3n42b3n44234234.jpg) so you need to show this renamed image. Thus you need to add
config.assets.digest = true
this to your production.rb
Upvotes: 1
Reputation: 6100
If you display images like
<img src='src_of_your_image'>
This will not work, because of asset pipeline, you have to use image_path
helper
<%= image_path 'src_of_your_image' %>
Image path helper will properly render you image even in production mode, after your images get their path distorted with custom hash.
Upvotes: 0