Search code examples
ruby-on-railsruby-on-rails-3activerecordattrmass-assignment

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


I have user model with use of devise gem, I dont have attr_accessible for any fields still I get the error:

Can't mass-assign protected attributes

My User class as below

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, 
         :token_authenticatable  #, :validatable
end

Solution

  • I also have the same problem, maybe devise does something with attr_accessible. You need to set up attr_accessible in your model to make it work.

    class User < ActiveRecord::Base
      devise :database_authenticatable, :registerable,
    :recoverable, :rememberable, :trackable, :token_authenticatable #, :validatable`
    
      # Setup accessible (or protected) attributes for your model
      attr_accessible :first_name, :last_name, :email, :password, :password_confirmation
    end
    

    You can checkout these railscasts episodes.

    http://railscasts.com/episodes/209-introducing-devise

    http://railscasts.com/episodes/210-customizing-devise