can't permit custom params with strong paramet

2019-07-20 15:23发布

I want to permit nested custom parameters but am not sure how to access them.

These are my params:

params=> 
  {"utf8"=>"✓",
   "authenticity_token"=>"...",
   "tracking"=>{"installation"=>"4", "code"=>[{"1"=>"one", "2"=>"two"}]},
   "action"=>"create",
   "controller"=>"admin/trackings"}

According to the Strong Parameters documentation I tried some combinations like this:

def tracking_params
  params.require(:tracking).permit(:installation, code: [])
end

but they are not working. What am I missing?

2条回答
SAY GOODBYE
2楼-- · 2019-07-20 15:36
def tracking_params
  params.require(:tracking).permit(:installation, {:code => []})
end
查看更多
劫难
3楼-- · 2019-07-20 15:46

Have you tried solving this on the model level? I think you just need to add:

accepts_nested_attributes_for :tracking

Not sure what your Rails version is, but the docs for Rails 5.1.2 seem to cover this

查看更多
登录 后发表回答