如何在回形针中什么都不显示而不是丢失图像

how to show nothing instead of missing image in paperclip

我正在使用回形针上传我的照片。如果照片未上传,它会显示丢失的图像而不整洁,我不想渲染任何东西来代替丢失的图像。

this is my index.html.erb  view

<tbody>
    <% @products.each do |product| %>
      <tr>
        <td><%= product.title %></td>
        <td><%= product.dscription %></td>

         <% if product.photo.nil?%>
         render 'nil'
          <% else %>
          <td><%=image_tag product.photo.url(:thumb) %></td>
          <% end %>
         <% if product.photo1.nil?%>
          <td><%=image_tag nil %></td>
          <% else %>
          <td><%=image_tag product.photo1.url(:thumb) %></td>
          <% end %>

尝试在您的代码中使用它来获取您选择的替代文本:

 <%= image_tag product.photo.url(:thumb)%> 

因为没有图片你什么都不想要。做这样的事情:

config/initializers

下添加
module ActionView::Helpers::AssetTagHelper
  def image_alt(src)
    return ''
  end
end

有人问过同样的问题 earlier。 在提问之前请正确搜索。