我想在 rails_admin
中为我的每个产品制作类似照片库的内容。
但对于不同的产品,我想添加不同数量的照片。
所以,我的 Product
模型与 has_one :gallery
关联,我的 Gallery
模型与 belongs_to :product
关联。
当我不知道我究竟需要多少个字段时,如何在 rails_admin 模型
中拥有多个字段?
或者如何在rails_admin中通过Paperclip上传多个文件?
最佳答案
您可以使用accepts_nested_attributes_for
class Photo < ApplicationRecord
belongs_to :gallery, inverse_of: photos
has_attached_file :image
end
class Gallery
has_many :photos
accepts_nested_attributes_for :photos
end
这会给你带来这样的结果:
注意如何可以拥有任意数量的照片。
关于ruby-on-rails - Rails_admin 多图片上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20637860/