I have a nested form in ActiveAdmin for these models (a :class_section has_many :class_dates):
class ClassDate < ActiveRecord::Base
belongs_to :class_s
You need to permit nested parameters, but you should never use params.permit!
. It's extremely unsafe. Try this:
ActiveAdmin.register ClassSection do
permit_params :max_students, :min_students, :info, :class_course_id, :location_id,
class_dates_attributes: [ :id, :start_time, :end_time, :_destroy ]
form do |f|
# ...
f.inputs "Dates" do
f.has_many :class_dates, heading: false, allow_destroy: true do |cd|
cd.input :start_time, :as => :datetime_picker
cd.input :end_time, :as => :datetime_picker
end
end
f.actions
end
# ...
end
The configuration (and permitted_params
) of your ClassDate
admin panel has nothing to do with the permitted parameters within the ClassSection
admin panel. Treat them as separate controllers within the app.
Adding the allow_destroy: true
option to the has_many
call will add a checkbox to the form to allow you to delete a class time upon form submission.