<%best_sellers = Spree::Taxonomy.find_by_name("Best Seller").root.products.limit(6)%>
<%best_sellers.each do |best_seller_array|
<div class="card card-custom text-center rounded w-25">
<%= image_tag main_app.url_for(best_seller_array&.attachment),class:"img-fluid" %>
<a href=""><%= best_seller_array.name%> </a>
</div>
<%end%>

发布于 2021-12-22 06:04:20
在狂欢节中,产品has_many :images,所以如果您想要显示任何产品图像,您可以尝试如下所示-
<%= image_tag main_app.url_for(product&.images&.first&.attachment), class: "img-fluid" %>如果您想显示产品的所有图像,那么只需遍历如下所示的图像循环
<% best_sellers_products.each do |product| %>
<% product.images.each do |image| %>
// display image
<% end %>
<% end %>希望这能解决问题。
谢谢
https://stackoverflow.com/questions/70314681
复制相似问题