Search code examples
ruby-on-railsstrong-parameters

Strong parameters definition issue


Employee controller has the following definition for params. Positions attribute seems init correctly.

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

The error I am getting is the following: enter image description here


Solution

  • If you want to put not enclosed in {} hash, it's only possible if this is the last parameter of the method. This is not the case in your example, so you should change your code a little bit:

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