I have two models Degree and College connected many_to_many connection via Discipline table.
class Degree < ActiveRecord::Base
has_many :disciplines
has_many :colleges, :through => :disciplines
end
class Discipline < ActiveRecord::Base
belongs_to :college
belongs_to :degree
end
class College < ActiveRecord::Base
has_many :disciplines
has_many :degrees, :through => :disciplines
end
I want to display multiple select (or checkboxes) with a degrees on the college new/update forms. How to do that?
In the College ActiveAdmin resource you can use the has_many
method in the form block:
ActiveAdmin.register College do
#...
form do
#...
f.has_many :disciplines do |df|
df.input :degree
end
#...
end
#...
end
This will be a multiselect select input by default. Find out more: https://github.com/activeadmin/activeadmin/blob/master/docs/5-forms.md#nested-resources
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.