2015-10-09 57 views
1

我在活動管理資源中使用嵌套表單,但嵌套屬性的值未保存在模型中。active_admin的不允許參數嵌套表格

這裏是我的模型的細節 -

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 

,這裏是從我的積極超越的有效管理資源::評估

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 

admin表格我填寫了exceed_assessment和嵌套表格assessment_info的詳細信息。 Exceed_assessment詳細信息已成功保存在模型中,但assessment_info未保存。 當我檢查它在控制檯上顯示它的錯誤消息 -

Unpermitted parameters: assessment_infos_attributes 
Unpermitted parameters: utf8, authenticity_token, commit 

回答

0

我做了一些愚蠢的錯誤,經過改正其工作。

首先,在我的Assessment_info模型中有一列'exceed_assessment_id'。我將它更改爲'assessment_id',因爲我的模型是belongs_to評估模型。

其次,我稍微改變許可證則params的語法,這樣的 -

controller do 
    def permitted_params 
     params.permit exceed_assessment: [:id, :exceed_id, :exceed_section_id, :guideline, 
     assessment_infos_attributes: [:assessment_id, :information],] 
    end 
    end