载波。具有多个上载器的多态附件

时间:2018-08-14 19:32:45

标签: ruby-on-rails carrierwave

我有几个带有附件的模型

每个人都有不同的Uploader

我可以通过多态关联将上传器保存(装入)并用于不同模型的不同Uploader文件吗?

例如

class User < ApplicationRecord
  mount_uploader :avatar, AvatarUploader
  has_many :attachments, as: :attachment
end

class Article < ApplicationRecord
  mount_uploader :picture, PictureUploader
  has_many :attachments, as: :attachment
end

class Attachment < ApplicationRecord
  belongs_to :attachment, polymorphic: true
end

有可能吗?

0 个答案:

没有答案