Yaro
Yaro

Reputation: 568

rails_admin multiple image uploading?

I want to make something like gallery of photos for each of my product in rails_admin.

But for different products I want to add different amount of photos.

So, I've got my Product model with has_one :gallery association and my Gallery model with belongs_to :product association.

How can I have multiple fields in rails_admin model, when I don't know how many fields, will I need exactly?

Or how can I upload multiple files through Paperclip in rails_admin ?

Upvotes: 2

Views: 1532

Answers (1)

Guillermo Siliceo Trueba
Guillermo Siliceo Trueba

Reputation: 4619

You could use accepts_nested_attributes_for

class Photo < ApplicationRecord
   belongs_to :gallery, inverse_of: photos
   has_attached_file :image
end

class Gallery 
   has_many :photos
   accepts_nested_attributes_for :photos
end

And this would get you something like this:

enter image description here

Notice how you could have as many photos as you want.

Upvotes: 3

Related Questions