提问人: 提问时间:4/13/2022 最后编辑:Deepesh 更新时间:4/14/2022 访问量:72
如果未附加图像,则在 bootstrap 上显示默认法师
showing a default mage on bootstrap if images are not attached
问:
我在引导轮播中,我想调用一个方法,如果它们被附加,它将播放轮播中的图像,如果它们没有附加,它将播放默认图像(在轮播中)。
这是我的方法:
def bien_picture_carousel
if images.attached?
images.each do |image|
image.key
end
else
"bien-par_defaut_shvulu"
end
end
这是我的引导轮播迭代(我的轮播在没有调用方法的情况下运行良好)
<% @bien.images.each.with_index do |image, i| %>
<div class="carousel-item >
<%= cl_image_tag @bien.bien_picture_carousel%> **<--- error is on this line**
</div>
<% end %>
问题:我有此错误消息:« 没有将 ActiveStorage::Attachment 转换为字符串的隐式转换 »
我真的不明白这个错误消息。 我能做些什么来让它工作?
编辑:
我已经更新了我的方法:
<div class="carousel-inner">
<% if @bien.images.attached? %>
<% @bien.images.each.with_index do |image, i| %>
<div class="carousel-item" >
<%= cl_image_tag image.key%>
</div>
<% end %>
<% else %>
<% @bien.images.each.with_index do |image, i| %>
<div class="carousel-item" >
<%= cl_image_tag "bien-par_defaut_shvulu" %>
</div>
<% end %>
<% end %>
其他部分未显示在屏幕上
答:
0赞
user18341951
4/14/2022
#1
解决
缺少一个活动类。
我替换了
<% else %>
<div class="carousel-item" >
<%= cl_image_tag "bien-par_defaut_shvulu" %>
</div>
<% end %>
<% end %>
由
<% else %>
<div class="carousel-item active" >
<%= cl_image_tag "bien-par_defaut_shvulu" %>
</div>
<% end %>
评论