需要 link 图片到 post

need to link image to post

我需要 link 一张图片到 post 它匹配。任何关于如何实现这一点的帮助都会很棒!

<% @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>

<%= link_to (image_tag(...)), target_url %> 应该可以。适当指定 image_tag params & target_url

在您的代码中,<% image_tag "{https://dl-web... 实际上应该是 <%= image_tag "{https://dl-web... 才能显示图像。 <% .. %> 仅计算其中的表达式,而 <%= .. %> 计算表达式并包括其输出。