简体   繁体   中英

One Carrierwave Uploader shared between Two Models in ActiveAdmin

I have one CarrierWave Uploader called documents .

Three Models:

  1. University has_many :documents
  2. WebinarContent has_many :documents
  3. Document
    belongs_to :university
    belongs_to :webinar_content

I currently have ActiveAdmin setup: 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:

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

Basically you want your document to belongs_to :documentable having a documentable_id and a documentable_type on the Document model.

Then on your other models you wish to upload documents to you have has_many :documents

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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