[英]How to convert strong parameter rails 4
My form sends data like 我的表单发送数据像
{"utf8"=>"✓",
"authenticity_token"=>"",
"org_document"=>{"is_fin_changed"=>"Y"},
"commit"=>"Save",
"document_type"=>"FIN_CART"}
So, I wrote strong parameter like 所以,我写了像
def req_document_params
params.fetch(:org_document,{}).permit(:document_type,:is_fin_changed)
end
But it only sends {"is_fin_changed"=>"Y"}
Not sure what is wrong! 但是它只发送
{"is_fin_changed"=>"Y"}
不确定什么地方出错了! Any help appreciated:) 任何帮助表示赞赏:)
In your case fetch
method return value of :org_document
so it returns {"is_fin_changed"=>"Y"}
then you call permit
, but in {"is_fin_changed"=>"Y"}
there isn't :document_type
在你的情况下
fetch
方法的返回值:org_document
所以它返回{"is_fin_changed"=>"Y"}
然后调用permit
,但在{"is_fin_changed"=>"Y"}
没有:document_type
Try 尝试
def req_document_params
params.require(:org_document).permit(:is_fin_changed).merge(params.permit(:document_type))
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.