Andrew
Andrew

Reputation: 43103

Cannot permit parameters?

This is bizarre to me, so I'm just curious if anyone else has run into this:

I've got the following:

def credential_params
  params.required(:credential).permit(:name,:agent_ids)
end

In my controller create and update actions I'm using mass assignment with the above parameter call...

@credential.update_attributes(credential_params)

But I still get Unpermitted parameters: agent_ids

If I change this to params.required(:credential).permit! (ie permit all) of course it works.

I feel like I must be overlooking some obvious gotcha here... anyone know what it might be?

Upvotes: 5

Views: 2498

Answers (2)

Andrew
Andrew

Reputation: 43103

Got it.

An array isn't one of the supported types:

The permitted scalar types are String, Symbol, NilClass, Numeric, TrueClass, FalseClass, Date, Time, DateTime, StringIO, IO, ActionDispatch::Http::UploadedFile and Rack::Test::UploadedFile.

Therefore the solution is to specify an array, like so:

params.require(:credential).permit(:name, :agent_ids => [])

Hope others find this useful.

Upvotes: 5

jvnill
jvnill

Reputation: 29599

try

params.require(:credential).permit(:name, { :agent_ids => [] })

Upvotes: 6

Related Questions