ActiveModel ForbiddenAttributesError

时间:2017-12-08 01:08:37

标签: ruby-on-rails activeadmin

请帮帮我。 Rails发誓...... 我应该改变什么?我允许所有参数(permit_params),但这没有帮助:

cd /
du -x

" config.action_controller.permit_all_parameters = true"解决了这个问题。但我不想禁用strong_parameters。

更新

应用程序/管理/ user.rb

ActiveModel::ForbiddenAttributesError

Extracted source (around line #17):          
@user            = User.where(id: params[:id]).first_or_create
@user.superadmin = params[:user][:superadmin]
@user.attributes = params[:user].delete_if do |k, v|
  (k == "superadmin") ||
  (["password", "password_confirmation"].include?(k) && v.empty? && !@user.new_record?)
end

P.S。我参与了这个guide。 问题与此问题非常相似:I get ActiveModel::ForbiddenAttributesError with Active Admin and Devise我在管理面板ActiveAdmin中创建新用户时出现此错误。

UPDATE1

控制台

ActiveAdmin.register User do

form do |f|
f.inputs "User Details" do
  f.input :email
  f.input :password
  f.input :password_confirmation
  f.input :superadmin, :label => "Super Administrator"
end
f.actions
end

create_or_edit = Proc.new {
@user            = User.where(id: params[:id]).first_or_create
@user.superadmin = params[:user][:superadmin]
@user.attributes = params[:user].delete_if do |k, v|
  (k == "superadmin") ||
  (["password", "password_confirmation"].include?(k) && v.empty? && !@user.new_record?)
end
if @user.save
  redirect_to :action => :show, :id => @user.id
else
  render active_admin_template((@user.new_record? ? 'new' : 'edit') + '.html.erb')
end
}

member_action :create, :method => :post, &create_or_edit
member_action :update, :method => :put, &create_or_edit

permit_params :authenticity_token, :commit, :id, user: [:email, :password, :password_confirmation, :superadmin]

end

1 个答案:

答案 0 :(得分:0)

我必须同意您提到的问题的答案,per the doc请尝试:

permit_params :email, :password, :password_confirmation, :superadmin