Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 619
Andrew Avatar asked Jan 14 '23 23:01

Andrew


2 Answers

try

params.require(:credential).permit(:name, { :agent_ids => [] })
like image 137
jvnill Avatar answered Jan 19 '23 11:01

jvnill


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.

like image 30
Andrew Avatar answered Jan 19 '23 12:01

Andrew