简体   繁体   English

在ActiveAdmin中的两个模型之间共享一个载波上传器

[英]One Carrierwave Uploader shared between Two Models in ActiveAdmin

I have one CarrierWave Uploader called documents . 我有一个CarrierWave Uploader,称为文档

Three Models: 三种型号:

  1. University has_many :documents 大学has_many:文件
  2. WebinarContent has_many :documents WebinarContent has_many:文档
  3. Document 文献
    belongs_to :university 所属:大学
    belongs_to :webinar_content 当属:网络研讨会内容

I currently have ActiveAdmin setup: app/admin/document.rb 我目前有ActiveAdmin设置: app / admin / document.rb

belongs_to :university

That works well, however, when I try adding another belongs_to :webinar_content association, I get the following error: 效果很好,但是,当我尝试添加另一个belongs_to:webinar_content关联时,出现以下错误:

Couldn't find University with 'id'=

Any idea on how to resolve this? 关于如何解决这个问题的任何想法?

Without seeing your schema, its hard to tell. 没有看到您的架构,很难分辨。 Though I suspect you want polymorphic associations. 虽然我怀疑您想要多态关联。

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

Basically you want your document to belongs_to :documentable having a documentable_id and a documentable_type on the Document model. 基本上,你希望你的文档belongs_to :documentabledocumentable_iddocumentable_typeDocument模型。

Then on your other models you wish to upload documents to you have has_many :documents 然后在其他模型上,您希望将文档上载到has_many :documents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM