强参数定义问题

时间:2019-12-19 08:51:49

标签: ruby-on-rails strong-parameters

Employee控制器对参数具有以下定义。 Positions属性似乎初始化正确。

def employee_params
  params.fetch(:employee, {}).permit(
    :note,
    positions_attributes: [:id, :branch_id , :department_id, :employee_id],
    :work_type)
end

我得到的错误如下: enter image description here

1 个答案:

答案 0 :(得分:1)

如果要不将其放在{}哈希中,则仅当它是方法的最后一个参数时才有可能。在您的示例中不是这种情况,因此您应该对代码进行一些更改:

def employee_params
  params.fetch(:employee, {}).permit(:note, :work_type,
                                     positions_attributes: [:id, :branch_id , :department_id, :employee_id])
end