I would like to add an image in my template for my ruby on rails project where i currenly have the code <img src="../../../public/images/rss.jpg" alt="rss feed" />
in a the layout stores.html.erb
file however this doesn't seem to load as it looks like its missing a route which i'm not sure what its supposed to be.
Any ideas please?
When using the new ruby, the image folder will go to asset folder on folder app
after placing your images in image folder, use
simple just use the img tag helper. Rails knows to look in the images folder in the asset pipeline, you can use it like this
In a Ruby on Rails project by default the root of the HTML source for the server is the public directory. So your link would be:
But it is best practice in a Rails project to use the built in helper:
That will create the correct image link plus if you ever add assert servers, etc it will work with those.
It's working for me:
<%= image_tag( root_url + "images/rss.jpg", size: "50x50", :alt => "rss feed") -%>
image_tag is the best way to do the job friend
Anything in the
public
folder is accessible at the root path (/
) so change your img tag to read:If you wanted to use a rails tag, use this: