我試圖用繭寶石保存嵌套模型。這裏是PARAMS JSON:Rails 5:未經許可的參數
Parameters: {
"utf8" => "✓",
"authenticity_token" => "w/hwSu6yvT/R+6KFdoi7L6v3tDYJppiXyvQigBfTpD6EuTVz9P2CKImybxgip90YA0Yo7QKpID+IeCi2KLsy0g==",
"project" => {
"client" => "1", "name" => "Project 1", "instances_attributes" => {
"1508163439344" => {
"instances" => {
"user_id" => "user1", "password" => "[FILTERED]", "service_url" => "http://localhost:3001"
}
}, "1508163446859" => {
"instances" => {
"user_id" => "user2", "password" => "[FILTERED]", "service_url" => "http://localhost:3002"
}
}
}
},
"commit" => "Create Project"
}
對於強參數代碼項目的控制器:
def project_params
params
.require(:project)
.permit(
:client, :name,
instances_attributes: Instance.attribute_names.map(&:to_sym).push(:_destroy)
)
end
現在,當我試圖挽救它顯示我:Unpermitted parameter: instances
我缺少什麼?
你試過instance_attributes,奇異?此外,我認爲你必須通過:ID屬性的繭列表,但我不知道 –
:id正在處理'Instance.attribute_names.map(&:to_sym)' –
@RajMishra檢查我的解決方案。它應該爲你工作 – krishnar