简体   繁体   中英

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! 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

Try

 def req_document_params
   params.require(:org_document).permit(:is_fin_changed).merge(params.permit(:document_type))
 end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM