2

The images that I am using in my index.html.erb file are in the assets/images directory. I have deployed the app to heroku but it is not showing the images. I am linking the images using tag in the html file and not in the css file.

Please help.

4
  • possible duplicate of Rails 3.1 and Image Assets Commented Jun 10, 2014 at 1:45
  • Post some snippets from your erb file as well as the output in the browser and server consoles. Commented Jun 10, 2014 at 5:14
  • Have you double checked your configuration files ? Commented Jun 10, 2014 at 6:41
  • Got a link we could look at? Commented Jun 10, 2014 at 7:00

2 Answers 2

3

If your images are part of your asset pipeline (I.E assets/images), you should be able to access them relatively simply with Heroku, especially if you're using image_tag to do this (rather than css)

--

Precompile

Since Heroku relies on your assets being static (precompiled), I would make sure the assets are precompiled on the system, and that you're referencing them correctly:

#cmd $ heroku run rake assets:precompile 

This will precompile the assets on Heroku's system (which should have been done anyway), ensuring your app should be able to access the files correctly. This is the first thing to test, as it's often the case the files will remain non-compiled, preventing Heroku from reading them

--

Images

In reference to your images, you need to know from the asset pipeline that calling image_tag "your_image.png should automatically call assets/images, vendor/assets/images and public/assets/images to pull the correct file

If this works in local, it means your paths are okay. If it does not work in local, it means your paths are incorrect, and the issue will be with your code.


You should provide a link to your Heroku app and show us the HTML / erb files you're using

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

Comments

1

If your images are indeed in that folder then you can use this method here How to reference images in CSS within Rails 4

But if your uploading images into your Rails app via Carrierwave then you need to use an external image hosting provider such as Cloudinary. This is because the Heroku environment is refreshed each git push so any files on the server that were uploaded, since they're not on the client git side, are removed.

You can run heroku run bash to look around your directories on Heroku to verify if the image is there.

EDIT

In regular views you can access images in the public/assets/images directory like this:

<%= image_tag "rails.png" %> 

Source: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

1 Comment

You see the problem is: My images are not refernced in stylesheet that is inside CSS files. I have referenced them inside HTML files and I need to keep it that way, so given that how do I make the images appear after deploying to heroku

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.