Thermatix Thermatix - 3 years ago 471
Ruby Question

ActiveAdmin Unpermitted Parameters despite being whitelisted

I've whitelisted the params like so:

permit_params(%i{identity os current_ip clients site_ids sites domains})


but I get the following in the log:

{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"aU8vwoMbWcMikSQLSGuVo5XTF+sAopRi0+OhgxXYvSKD9UbLaImB3k+uhf03PpWNiwtrZrEv0wVpT9pIcCkyag==", "server"=>{"identity"=>"", "os"=>"UBUNTU 14.04", "current_ip"=>"123.245.23.24", "site_ids"=>["", "1"]}, "commit"=>"Update Server", "controller"=>"admin/servers", "action"=>"update", "id"=>"1"}
Server Load (0.2ms) SELECT "servers".* FROM "servers" WHERE "servers"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Unpermitted parameters: :site_ids


My form looks like:

form do |f|
f.inputs "Server Details" do
f.input :identity
f.input :os, label: 'OS'
f.input :current_ip, as: :string
f.input :sites, as: :select, collection: Site.all
end
f.actions
end


Why are params not being allowed despite being whitelisted?

Answer Source

You need to use array syntax for site_ids:

[:identity, :os, :current_ip, :clients, :sites, :domains, site_ids: []]

So it'd be something like this:

permit_params([:identity, :os, :current_ip, :clients, :sites, :domains, site_ids: []])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download