※プログラミング学習中の私がアップロードしてます。理解が浅いです。
この記事は厳密な仕様に関するものではなく、考え方理解のまとめとして受け取ってください。
現在、フリーマーケットアプリの開発中です。
環境
Rails 6.0.3.6
Activestorage 6.0.3.6
Ruby 2.6.5p114
Devise 4.7.3
現在写真投稿機能にプレビュー機能を追加が終わり、続いて複数枚投稿機能を実装中です。
写真に関する複数枚表示を実装しております。
エラー
こちらのエラーについては同じく受講生さんの@zuu_aaさんの投稿で解決出来そうだと考えたのですが、
これだと1枚目(images[0])に限定するので悩んでいました。
結果は以下

もう一度ブロック変数で取れている中身を確認し見ると
<%= link_to item_path(item.id) do %>
<div class='item-img-content'>
<% item.images.each do |i| %>
<%= image_tag item.images[0], class: "item-img" %>
<% if item.purchase.present? %>
>> i
=> #<ActiveStorage::Attachment id: 41, name: "images", record_type: "Item", record_id: 39, blob_id: 41, created_at: "2021-05-15 07:38:54">
>> item.images
=> #<ActiveStorage::Attached::Many:0x00007fccdaa34fb8 @name="images", @record=#<Item id: 39, item_name: "www", description: "www", category_id: 3, status_id: 2, delivery_fee_payment_id: 3, prefecture_id: 2, delivery_prepare_id: 2, price: 3400, user_id: 2, created_at: "2021-05-15 07:38:54", updated_at: "2021-05-15 07:38:54">>
というふうに取得できているので
以下のように書き換えるとうまくいきました。
<% @item.images.each do |i| %>
<%= image_tag i, class:"item-box-img" %>
<%# 商品購入後実装 %>
<% if @item.purchase.present?%>
<div class="sold-out">
<span>Sold Out!!</span>
</div>
<% end %>
<% end %>

