Terminal58
Terminal58

Reputation: 577

Can't add more then one image_tag

This code in the ERB only displays one image. I thought it would be a simple fix but I've scoured google trying to find it. Maybe I'm just forgetting something

<%=
image_tag ruby.png
image_tag ruby.png %>

Upvotes: 2

Views: 106

Answers (2)

vijikumar
vijikumar

Reputation: 1815

If we want to display in the screen, we have to use the equal (=) symbol.

Please modify your code like this..

<%=image_tag ('ruby.png') %>

<%=image_tag ('ruby.png') %>

ELSE if you have more images. collect it in a array and do the following.

all_images=[image1.png,image2.png,image3.png,image4.png,image5.png,....imagex.png]

then

all_images.each do |image_name|

<%=image_tag ('image_name')%>

end

Upvotes: 0

Beno&#238;t
Beno&#238;t

Reputation: 15010

<%= %> prints the result of the code inside it, not all of it. If you want to display two images, you can do

<%= image_tag('ruby.png') %>
<%= image_tag('ruby.png') %>

or

<%= image_tag('ruby.png') << image_tag('ruby.png') %>

or

<%
  concat(image_tag('ruby.png'))
  concat(image_tag('ruby.png'))
%>

Upvotes: 4

Related Questions