0
votes

I am developing simple web application in ruby on rails 3, where users can upload images and uploaded all images has to be displayed. Successfully i uploaded images into folder(photos) which is located in public and stored their url path in database.I am getting problem in displaying images.

image.html.erb

<% @photo.each do |photo| %>
  <table>
    <tr> 
      <td><img src = "#{photo.url}" /></td>
    </tr>
  </table>
<%end%>

in photos controller

def image
  @photo = Photo.all
end

when iam giving path(photos/pic1.jpg) the loop has been working but it displaying only one image, if iam using photo.url it has been not displaying any image.

1

1 Answers

1
votes

To render some variable value into erb template you should use <%= ... %> instead of regular string interpolation #{...}. In your case you can do:

<img src = "<%= photo.url %>" />

Or, better, you can use image_tag helper:

<%= image_tag photo.url %>