Add image to layout in ruby ​​on rails

I would like to add an image to my template for my ruby ​​on rails project, where I always have the code <img src="../../../public/images/rss.jpg" alt="rss feed" /> in the stores.html.erb layout stores.html.erb , however this doesn't seem to load as it looks like its missing route, which I'm not sure what it should be.

Any ideas please?

+55
ruby ruby-on-rails image layout
Nov 29 '09 at 5:25
source share
6 answers

Everything in the public folder is available in the root path ( / ), so change your img tag as follows:

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

If you want to use the rails tag use this:

 <%= image_tag("rss.jpg", :alt => "rss feed") %> 
+119
Nov 29 '09 at 5:31
source share

In a Ruby on Rails project, by default, the root of the HTML source for the server is the public directory. So your link will be as follows:

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

But in a Rails project, it's better to use the built-in helper:

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

This will create the correct link to the image plus, if you ever add claim servers, etc., it will work with them.

+12
Nov 29 '09 at 5:36
source share

When using a new ruby, the folder with images will go to the folder with the folder in the folder

after placing the images in the image folder use

 <%=image_tag("example_image.png", alt: "Example Image")%> 
+4
Jan 23 '13 at 6:35
source share

just use the img tag helper. Rails knows what to look for in the image folder in the asset pipeline, you can use it as follows

 <%= image_tag "image.jpg" %> 
+1
Mar 28 '16 at 0:56
source share

It works for me:

<%= image_tag( root_url + "images/rss.jpg", size: "50x50", :alt => "rss feed") -%>

+1
Feb 23 '17 at 11:41
source share

image_tag is the best way to make work friend

0
Nov 24 '17 at 15:56
source share



All Articles