2017-09-29 38 views
0

我的形式向外發送數據,如如何轉換強勁參數軌道4

{"utf8"=>"✓", 
"authenticity_token"=>"", 
"org_document"=>{"is_fin_changed"=>"Y"}, 
"commit"=>"Save", 
"document_type"=>"FIN_CART"} 

所以,我寫強參數一樣

def req_document_params 
    params.fetch(:org_document,{}).permit(:document_type,:is_fin_changed) 
end 

但它僅發送{"is_fin_changed"=>"Y"}不知道什麼是錯的! 任何幫助表示讚賞:)

+0

別你看到'document_type'超出'org_document'參數嗎?顯示與該請求相關的代碼。 –

+0

我給出了與請求相關的代碼。不知道如何包含':document_type' – learner2017

+1

爲什麼人們把-1投爲建設性問題。你不覺得那個作者只有一個名聲嗎?而不是把答案投下來:/ –

回答

0

:org_document你的情況fetch方法的返回值,以便它返回 {"is_fin_changed"=>"Y"}然後調用permit,但在{"is_fin_changed"=>"Y"}沒有:document_type

嘗試

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