I have these associations:
class Course < ActiveRecord::Base
has_many :signup
has_many :user, :through => :signup
accepts_nested_attributes_for :signup
end
class User < ActiveRecord::Base
has_many :signup
has_many :course, :through => :signup
accepts_nested_attributes_for :signup
end
class Signup < ActiveRecord::Base
belongs_to :course
belongs_to :user
end
Now, I would like to customize the ActiveAdmin form for “Signup”, so it shows the title of the courses and the name of the users as a select and not as a textfield.
The default form already does that, however I need to customize the form further and I can’t reproduce the default form.
Your form block will look something like this in your
admin/signups.rb:By default, since
courseanduserare associations, this should give you acollection_select– that is, a with thenameattribute of your models as labels,ids as values. If you had passed yourinputs a input type, this will force them to display as that type.This’ll just give you a
course_idtext input field, where you’ll probably just enter the ID for the associated object. To “reproduce the default form”, just continue addinginputs for the relevant attributes. You can even wrap them inf.inputsto group them and make things look pretty.