ActiveAdmin Unpermitted Parameters despite being whitelisted
Asked Answered
W

2

6

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?

Walli answered 2/10, 2017 at 7:53 Comment(0)
P
13

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: []])
Professor answered 2/10, 2017 at 8:2 Comment(0)
W
0

Rails 6

ActiveAdmin.register Record do
  permit_params :start_date, :classroom_id, :teacher_id, group_ids: []

From model:

class Record < ApplicationRecord
  has_and_belongs_to_many :groups, optional: true
Wynn answered 18/6, 2020 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.