Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin: Generating drop down list in form for has_many/belongs_to relationship

I have Gallery and Image models with has_many/belongs_to relationship.

My admin_active form for Image looks like this:

form do |f|
  f.inputs "Image Details" do
    f.input :gallery_id
    f.input :file
  end
end

Instead or entering number for gallery_id I'd like to chose gallery name from drop-down list. By deafault this form looks like this, but I don't know how to do this manually.

like image 782
Marcin Doliwa Avatar asked May 17 '13 18:05

Marcin Doliwa


2 Answers

Change your form to the following

form do |f|
  f.inputs "Image Details" do
    f.input :gallery_id, as: :select, collection: Gallery.select(:name).uniq
    f.input :file
  end
end
like image 75
Luís Ramalho Avatar answered Oct 31 '22 21:10

Luís Ramalho


Try this

form do |f|
  f.inputs "Image Details" do
    f.input :gallery
    f.input :file
  end
end
like image 33
James Avatar answered Oct 31 '22 19:10

James