Nested form in activeadmin not saving updates

前端 未结 1 1926
滥情空心
滥情空心 2020-12-14 23:14

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         


        
相关标签:
1条回答
  • 2020-12-14 23:32

    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.

    0 讨论(0)
提交回复
热议问题