dysbulic
dysbulic

Reputation: 3105

Unpermitted parameters error for permitted attributes

I have a rails app for doing volunteer scheduling. Shifts have multiple workers. I am trying to pass the worker ids from the edit form to the shifts controller.

The input form is being generated with the appropriate elements:

<select id="shift_workers" multiple="multiple" name="shift[workers][]">
  <option selected="selected" value="1">username</option>
</select>

In the controller I have the following code:

def shift_params
  params.require(:shift).permit(:start, :end, :size, :task_id, workers: [])
end

Despite this I am getting the following error when editing shifts:

Unpermitted parameters: workers

Upvotes: 2

Views: 1626

Answers (1)

Niall Paterson
Niall Paterson

Reputation: 3580

You have to do this:

workers_ids: []

Rather than this:

workers: []

because the database stores an array of the worker ids, not an array of workers.

Have a look here

Upvotes: 4

Related Questions