不允许具有强参数的自定义参数 [英] can't permit custom params with strong parameters

查看:96
本文介绍了不允许具有强参数的自定义参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许嵌套的自定义参数,但不确定如何访问它们.

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

这些是我的参数:

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?

推荐答案

您是否尝试过在模型级别解决此问题?我认为您只需要添加:

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

accepts_nested_attributes_for :tracking

不确定您的Rails版本是什么,但是 Rails 5.1的文档. 2 似乎涵盖了这一点

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

这篇关于不允许具有强参数的自定义参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆