ActiveAdmin 中两个模型共享一个 Carrierwave Uploader

One Carrierwave Uploader shared between Two Models in ActiveAdmin

我有一个名为 documents 的 CarrierWave 上传器。

三种型号:

  1. 大学 has_many:文档
  2. 网络研讨会内容 has_many:文档
  3. 文档
    belongs_to:大学
    belongs_to :webinar_content

我目前有 ActiveAdmin 设置: app/admin/document.rb

belongs_to :university

效果很好,但是,当我尝试添加另一个 belongs_to :webinar_content 关联时,出现以下错误:

Couldn't find University with 'id'=

知道如何解决这个问题吗?

没有看到你的模式,很难说。虽然我怀疑你想要多态关联。

http://guides.rubyonrails.org/association_basics.html#polymorphic-associations#polymorphic-associations

基本上,您希望文档 belongs_to :documentableDocument 模型上具有 documentable_iddocumentable_type

然后在您希望上传文件的其他型号上有has_many :documents