0
我想在其中一张照片为空白时显示默认图像,但它不起作用。 图像没有被绘制到HTML中,所以这是一个轨道问题。使用each_with_index时默认图像不显示
我的代码是:
<% photos = album.photos.limit(5) %>
<% photos.each_with_index do |photo, index| %>
<% if index == 0 %>
<img class="photo-album-element" src="<%= photo.photo_url(:big) %>" alt="">
<% else %>
<% if photo.present? %>
<img class="photo-album-element" src="<%= photo.photo_url(:thumb) %>" alt="">
<% elsif photo.blank? %>
<%= image_tag "default_album.png" %>
<% end %>
<% end %>
<% end %>
你是什么意思的“图像没有被绘成HTML”?所有照片都不显示?或者有些照片不显示?或者是否有任何错误消息?如果有更多信息,我们将能够提供更多建议。谢谢。 – 2014-10-02 15:07:52
嗨@AdlerHsieh,我的意思是默认图像不在DOM中,所以这是一个Rails问题,而不是URL问题 – Gibson 2014-10-02 16:20:39
当前存储的'default_album.png'在哪里? – PericlesTheo 2014-10-02 16:28:58