Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write pure HTML like <img> tag in ERB?

I want to replace <%= link_to image_tag ("picture.png") with something like this: <img src="/path/picture.png" /> in a file.html.erb

But when I do this, and it works without any error, but no picture shows up on the page.

like image 782
shravan Avatar asked Nov 17 '15 11:11

shravan


People also ask

How do I write on a IMG tag?

The <img> tag creates a holding space for the referenced image. The <img> tag has two required attributes: src - Specifies the path to the image. alt - Specifies an alternate text for the image, if the image for some reason cannot be displayed.

Which attributes are required for the IMG tag in HTML?

The img element has two required attributes: src : The source location (URL) of the image file. alt : The alternate text. This is used to describe the image for someone who cannot see it because they are either using a screen reader or the image src is missing.

Can I put an IMG inside an a tag?

Of course you can put an IMG tag inside an A tag. There's nothing wrong with it.

Why is my img tag not working?

Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.


1 Answers

You could do:

<img src="<%= image_path('picture.png') %>" />

But I don't see why this is better than:

<%= image_tag("picture.png") %>
like image 153
rlarcombe Avatar answered Oct 30 '22 03:10

rlarcombe