Reputation: 683
I need to link an image to the post it matches. Any help on how to accomplish this would be great!
<% @posts.each do |post| %>
<tr>
<td width="13%" height="120px">
<% if post.images.empty? %>
<% image_tag "{https://dl-web.dropbox.com/get/Duck%20Duck%20Jeep/Dollarphotoclub_70624208.jpg?_subject_uid=202757157&w=AACUcUehkUyn1S_gIrkrAtC0GKoAac2XAjCjZXHuwgapQA}", class: "thumbnail", class: "img-responsive" %>
<% else %>
<%= image_tag post.images.first.url, class: "thumbnail", class: "img-responsive" %>
<% end %>
</td>
<td><%= link_to post.heading, post %></td>
Upvotes: 0
Views: 40
Reputation: 13067
<%= link_to (image_tag(...)), target_url %>
should work. Specify the image_tag params
& target_url
appropriately.
In your code, the <% image_tag "{https://dl-web...
should actually be <%= image_tag "{https://dl-web...
for the image to show up. <% .. %>
only evaluates the expression within, whereas <%= .. %>
evaluates the expression and includes its output.
Upvotes: 1