ActiveAdmin未经许可的参数尽管列入白名单

时间:2017-10-02 07:53:43

标签: ruby ruby-on-rails-5 activeadmin

我已将这些参数列入白名单:

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

但我在日志中得到以下内容:

{"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

我的表单如下:

  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

为什么尽管被列入白名单但不允许使用params?

2 个答案:

答案 0 :(得分:6)

您需要使用site_ids的数组语法:

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

所以它是这样的:

permit_params([:identity, :os, :current_ip, :clients, :sites, :domains, site_ids: []])

答案 1 :(得分:0)

路轨6

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

来自模型:

class Record < ApplicationRecord
  has_and_belongs_to_many :groups, optional: true