【发布时间】:2015-10-09 19:39:56
【问题描述】:
我在活动管理资源中使用嵌套表单,但嵌套属性的值未保存在模型中。
这是我的模型的详细信息 -
class Exceed::Assessment < ActiveRecord::Base
has_many :assessment_infos, :class_name => "Exceed::AssessmentInfo", :dependent => :destroy
accepts_nested_attributes_for :assessment_infos, allow_destroy: true
end
下一个模型-
class Exceed::AssessmentInfo < ActiveRecord::Base
belongs_to :assessment
end
这里是 Exceed::Assessment 的活动管理资源
ActiveAdmin.register Exceed::Assessment do
form do |f|
f.inputs "Exceed Details" do
f.input :exceed_id, :label => 'Exceed Type', :as => :select, :collection => Exceed.all.map{|s| ["#{s.exceed_type}", s.id]}
f.input :exceed_section_id, :label => 'section', :as => :select, :collection => ExceedSection.all.map{|s| ["#{s.section}", s.id]}
f.input :guideline, label: "Section Guideline"
end
f.has_many :assessment_infos do |q|
q.input :information
end
f.actions
end
controller do
def permitted_params
params.permit exceed_assessment: [:exceed_id, :exceed_section_id, :guideline],
assessment_infos_attributes: [:information]
end
end
end
从我的活动管理表单中,我填写了超出评估和嵌套表单评估信息的详细信息。 Exceed_assessment 详细信息已成功保存在模型中,但assessment_info 未保存。 当我在控制台上检查它时,它会显示错误消息 -
Unpermitted parameters: assessment_infos_attributes
Unpermitted parameters: utf8, authenticity_token, commit
【问题讨论】: