Ruby on rails 分配与活动管理员的新多态关联

Ruby on rails 分配与活动管理员的新多态关联,ruby-on-rails,forms,ruby-on-rails-4,activeadmin,Ruby On Rails,Forms,Ruby On Rails 4,Activeadmin,我正试图修改我的活动管理员用户表单以修改用户的角色。这些角色是通过角色分配表的多态关联 当我提交表单时,角色没有更新,我想是因为关联的属性受到保护,并且我没有正确使用permit_参数 ActiveAdmin.register User do permit_params :email, :newsletter_subscription, :password, :password_confirmation, role_assignment_attributes:

我正试图修改我的活动管理员用户表单以修改用户的角色。这些角色是通过角色分配表的多态关联

当我提交表单时,角色没有更新,我想是因为关联的属性受到保护,并且我没有正确使用permit_参数

ActiveAdmin.register User do
  permit_params :email, :newsletter_subscription, :password, :password_confirmation,
                role_assignment_attributes: [:role_id, :user_id, :_destroy, :_create]
  ...
end
有什么想法吗?其他信息:

模式:

create_table "role_assignments", force: true do |t|
  t.integer  "role_id"
  t.integer  "user_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end
课程很简单:

class RoleAssignment < ActiveRecord::Base
  belongs_to :user
  belongs_to :role
end

class Role < ActiveRecord::Base
  has_many :role_assignments
  has_many :users, through: :role_assignments
  belongs_to :user
end
但是,当我提交表单时,没有分配任何内容。

像,您需要在
:role\u assignment\u attributes
中作为允许的参数传递
:id

permit_params :email, :newsletter_subscription, :password, :password_confirmation,
              role_assignment_attributes: [:id, :role_id, :user_id, :_destroy]
请注意,我删除了
:_create
参数,因为我从未见过类似的东西,所以我假设它是无意中添加的

permit_params :email, :newsletter_subscription, :password, :password_confirmation,
              role_assignment_attributes: [:id, :role_id, :user_id, :_destroy]