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.
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.
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
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