允许的参数仍然不允许

时间:2019-11-29 10:00:13

标签: ruby-on-rails strong-parameters

使用以下参数

  

参数:{“ authenticity_token” =>“”,   “ work_week_form” => {“ work_hours” => [{“ day” =>“ monday”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”},{“ day” =>“星期二”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”},{“ day” =>“星期三”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”},{“ day” =>“星期四”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”},{“ day” =>“星期五”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”},{“ day” =>“星期六”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”},{“ day” =>“星期日”,“ start_hour” =>“ 8”,   “ end_hour” =>“ 17”}]},“ button” =>“”}

为什么params.require(:work_week_form).permit(work_hours: [])加注Unpermitted parameter: :work_hours

1 个答案:

答案 0 :(得分:2)

在散列数组的情况下,您需要分别定义键,就像我们在父子关系的情况下需要指定键一样。 check here

您也可以检查解决方案here

params.require(:work_week_form).permit(work_hours: [:day, :start_hour, :end_hour])