当我尝试接受来自表单的嵌套属性时,我在日志中收到一个Unpermitted parameters: latitude, longitude, address
错误。确切的参数看起来像:
{
"widget"=> {
"owner"=>"100",
"name"=>"Widget Co",
"locations_attributes" => {
"0"=> {
"latitude"=>"51.4794259",
"longitude"=>"-0.1026201",
"address"=>"123 Fake Street"
}
}
},
"commit"=>"Create Supplier",
"action"=>"create",
"controller"=>"widgets"
}
一个小部件有_许多
个位置,一个位置属于
一个小部件。参数设置在 widgets_controller
中,我认为它会允许“0”以下的所有内容,但似乎不是?
def widget_params
params.require(:widget).permit(:owner, :name, locations_attributes: [{"0" => []}])
end
是否有有效/更好的方法来接受这些参数?
谢谢
最佳答案
试试这个
def widget_params
params.require(:widget).permit(:owner, :name, locations_attributes: [:id, :latitude, :longitude, :address])
end
关于ruby-on-rails - 如何允许嵌套属性的强参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30872461/