Reputation: 10208
I want an opinion and the Rails way to do something.
I have a Rails 3 application that uses active_admin gem. These app has some models. These models have one to many relationships with images. i.e. model A has many images, model B has many images, model C has many images.
I want to use paperclip (or another option) to store this images. I want to store all those images (from different entities) in the same table. In that table, i have to reference the entity using two columns (entity_type -A or B or C-, entity_id ). I cannot have a real foreign key because I don´t know which table I reference.
Questions are:
- What do you think about this database structure?
- How would you implement the image uploading functions using active_admin? In each model tab or an active admin model for the images and upload images for all models in the same tab?
- How can I implement that?
Upvotes: 1
Views: 1133
Reputation: 2182
Try https://github.com/gregbell/active_admin/issues/599 and then Macfanatics answer. It describes setting up a polymorphic association and how to use this within activeadmin.
Upvotes: 2