2

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?

3
  • Hi David, I have answered this question already, here's the link stackoverflow.com/questions/20104005/… Commented Jul 13, 2015 at 17:34
  • I'm not using paper clip or doing any image hosting. I just want to change my logo image. I hope I don't have to get Amazon s3 just to host one image. That's a bit ridiculous... Commented Jul 13, 2015 at 17:38
  • You can't save images in Heroku dynamically, only the assets images are served Commented Jul 13, 2015 at 17:44

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.