2016-12-02 6 views
0

私はちょうど@shiftのためのフォームを送信した後、私は私のコントローラで呼び出そう5.属性がRails 5のActionController :: Parametersオブジェクトの文字列として来るのはなぜですか?

をレールにアップグレード:

@position = Position.find params[:shift][:position_id]

私はエラー「整数にシンボルの暗黙の変換」を取得していません。

私はのparamsを確認してください。

<ActionController::Parameters {"shift"=>"#<ActionController::Parameters:0x007fecd4e83208>", "sms"=>"true", "controller"=>"admin/overtime", "action"=>"confirm"} permitted: true> 

私が呼び出す場合:params.to_h、私を得る:

{"shift"=>"#<ActionController::Parameters:0x007fecd4e83208>", "sms"=>"true", "controller"=>"admin/overtime", "action"=>"confirm"} 

シフトparamは"#<ActionController::Parameters:0x007fecd4e83208>"ある...文字列を!

私が行う場合:

params.require(:shift).permit(:position_id) 

は私が手:

NoMethodError: undefined method `permit' for "#<ActionController::Parameters:0x007fecd4e83208>":String 

はどのような値を取得することができますか?起こっていた

答えて

0

は私のShiftsControllerに私はOvertimeController確認アクションにリダイレクトされたことはなかった:Railsの5 ActionControllerで以来

admin_overtime_confirm_path(shift: params[:shift], sms: true) 

::パラメータは、もはやこれで、アプリケーション内のparamsをします呼び出し、HashWithIndifferentAccessから継承しますハッシュの代わりにオブジェクトを返します。そこで、ActionController :: Parametersオブジェクトの文字列バージョンを送信していました。

それを修正するために、私がやった:

admin_overtime_confirm_path(shift: params[:shift].permit!.to_h, sms: true) 
関連する問題