簡體   English   中英

我想在 ruby on rails 中顯示來自多張上傳照片的索引一 select 照片。 我能怎么做?

[英]I want to show in index one select photo from multiple upload photos, in ruby on rails. How can i do?

郵寄 Model

class Post < ApplicationRecord
    has_many_attached :images
end

Controller

params.require(:post).permit(:title, :body, images: [])

有人解釋我......

在索引中,您可以通過以下方式獲取第一張圖片:

@posts.each do |post|
  first_image = post.images.first # do something with it.
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM