ActiveAdmin: cannot assign secure attributes: email, password, password_confirmation

I have Rails with ActiveAdmin with Devise for Authentication. I have AdminUser and User models, so the user model does not have to worry about administration. However, I cannot create / edit either Adminuser or User FROM INSIDE on the admin page. Every time I try to do this, he will give me a message

Can't mass-assign protected attributes: email, password, password_confirmation 

This is strange because inside the User and AdminUser models I already have:

 attr_accessible :email, :password, :password_confirmation 

To try it another way, I went to the rails console and tried to create AdminUser, and it all worked:

 AdminUser.create(:email => ' asdf@admin2.com ', :password => 'password', :password_confirmation => 'password') 

This means that it was not possible to create only creation from the admin web page.

I am using Devise for Authentication. The error occurs with the User and AdminUser models.

For password and configuration_password, I do not have these fields in the database, but by default it is Devise by default, it never has a password in the database.

Here is the user model:

 devise :database_authenticatable, :registerable, :rememberable, :recoverable, :trackable, :omniauthable, :omniauth_providers => [:facebook] ##, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid # attr_accessible :title, :body validates :email, :password, :first_name, :last_name, presence: true validates :email, uniqueness: true has_many :devices has_many :posts 
+6
source share
1 answer

I am changing

 attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid 

to

 attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :as => [:default, :admin] 

and it works.

+8
source

Source: https://habr.com/ru/post/944844/


All Articles