0
0

More than 3 years have passed since last update.

[rails,active_storage]紐づいた画像のidの呼び出し方

Posted at

方法

今回は自分用ですが、皆さんのお役にも立つかと思ったため記述させてただきます

app/models/item.rb
〜前略〜
has_many_attached :images
〜後略〜
appcontrollers/items_controller
〜前略〜
def edit
  @item = Item.find(params[:id])
end
〜後略〜

上記の条件でactive_storageを紐づけている場合、下記の記述でimagesのidを表示できます

app/views/item/edit

= @item.images_blob_ids

おまけ

条件が同じの場合,全ての画像を表示する方法は下記の通りとなります。

app/views/item/edit
-@item.images.each do |image|
  =image_tag image
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0