Displaying Paperclip Image in index.html.erb view
I have successfully followed Ryan Bates tutorial of paperclip and have it working correctly. The image attaches to the record and displays on the show.html.erb.I am wondering how to display it on the index pages. Below is what I have tried but not working. For reference, the table is 'review' and the photo is 'photo'.
<table>
<tr>
<th>Photo</th>
<th>Review Title</th>
&开发者_JAVA技巧lt;th>Content</th>
<th>Name</th>
<th>Job Title</th>
<th>Company</th>
</tr>
<% @reviews.each do |review| %>
<tr>
<td><%=h review.photo.url %></td>
<td><%=h review.review_title %></td>
<td><%=h review.content %></td>
<td><%=h review.name %></td>
<td><%=h review.position %></td>
<td><%=h review.company %></td>
<td><%= link_to 'Show', review %></td>
<td><%= link_to 'Edit', edit_review_path(review) %></td>
<td><%= link_to 'Destroy', review, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
You'll want to use the image_tag
helper:
<td><%= image_tag review.photo.url %></td>
Its very simple to show a saved image. Use
<%= image_tag @model_variable.field_name.url %>
You can resize the image by giving the resolution like
<%= image_tag @model_variable.field_name.url, :size => "100x100" %>
精彩评论