views:

637

answers:

2

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?

+1  A: 

Anything in the public folder is accessible at the root path (/) so change your img tag to read:

<img src="/images/rss.jpg" alt="rss feed" />

If you wanted to use a rails tag, use this:

<%= image_tag("rss.jpg", :alt => "rss feed") %>
Doug Neiner
:o thanks a lot, i hadnt come across the image_tag silly me! , set yours as the accepted answer being first ;)
Erika
+1  A: 

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:

<img src="images/rss.jpg" alt="rss feed" />

But it is best practice in a Rails project to use the built in helper:

<%= image_tag("rss.jpg", :alt => "rss feed") %>

That will create the correct image link plus if you ever add assert servers, etc it will work with those.

ScottD
Bahaha. Our answers look identical. Great minds think alike (And I posted first :)
Doug Neiner
By a few minutes at best. I just needed to type faster.
ScottD
Haha. Yup! I knew you didn't copy it, that's why it was so funny ;)
Doug Neiner