Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am having a Rails with ActiveAdmin with Devise for Authentication. I have AdminUser and User models so that User model doesn't have to care about admin. However, I cannot create/edit neither Adminuser nor User FROM INSIDE the Admin page. Every time I try doing so, it will give me message

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

That's weird because inside User model and AdminUser models, I already have:

attr_accessible :email, :password, :password_confirmation

To try it other way, I went to rails console and try creating an AdminUser and it all worked:

AdminUser.create(:email => '[email protected]', 
    :password => 'password', :password_confirmation => 'password')

That means only creation from the Admin web page failed.

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

For password and password_confirmation, I don't have those fields in the Database, but that is the way Devise is by default, it never have password in 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
like image 375
u19964 Avatar asked May 13 '13 05:05

u19964


1 Answers

I change

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.

like image 116
u19964 Avatar answered Oct 20 '22 08:10

u19964