title: unknown attribute: password
body: <p>I got the error " unknown attribute: password"  while logging into the app. It doesn't seem to save the password. I am new to rails, can anyone help me on this? </p>
  
  <p>This is the message that I get while running the app. Here are is the code from model and control files. 
  ActiveRecord::UnknownAttributeError in UsersController#create </p>
  
  <h2>unknown attribute: password</h2>
  
  <p>I am trying to create a login/password web app. Getting the following error while running the app. 
  undefined method <code>encrypt_pasword'
  app/models/user.rb:32:in</code>password='
  app/controllers/users_controller.rb:43:in <code>new'
  app/controllers/users_controller.rb:43:in</code>create'</p>
  
  <p>Here is the code from control file.</p>
  
  <pre><code>require 'digest/sha2'
  class User &lt; ActiveRecord::Base
    include ActiveModel::MassAssignmentSecurity
  
    attr_accessible :name, :password, :password_confirmation, :hashed_password, :salt
    attr_accessor :name
    attr_accessor :salt
  
    validates :name, :presence =&gt; true, :uniqueness =&gt; true
    validates :password, :confirmation =&gt; true
    attr_accessor :password_confirmation
    attr_reader  :password
  
    validate :password_must_be_present
  
    def User.authenticate(name, password)
      if user = find_by_name(name)
        if user.hashed_password == encrypt_password(password, user.salt)
          user
        end
      end
    end
  
    def User.encrypt_password(password, salt)
      Digest::SHA2.hexdigest(password + "wibble" + salt)
    end
    # 'password' is a virtual attribute
    def password=(password)
      @password =password
      if password.present?
        generate_salt
        self.hashed_password =self.class.encrypt_password(password, salt)
      end
    end
    private
  
    def password_must_be_present
      errors.add(:password, "Missing password") unless hashed_password.present?
    end
  
    def generate_salt
      self.salt = self.object_id.to_s + rand.to_s
    end
  
  end
  </code></pre>
  
  <p>Here is  my model file </p>
  
  <pre><code>require 'digest/sha2'
  class User &lt; ActiveRecord::Base
    include ActiveModel::MassAssignmentSecurity
  
    attr_accessible :name, :password, :password_confirmation, :hashed_password, :salt
    attr_accessor :name
    attr_accessor :salt
    attr_accessor :password
  
    validates :name, :presence =&gt; true, :uniqueness =&gt; true
    validates :password, :confirmation =&gt; true
    attr_accessor :password_confirmation
    attr_reader  :password
  
    validate :password_must_be_present
  
       def encrypt_password
           self.encrypted_password 
      end
  
         def User.authenticate(name, password)
      if user = find_by_name(name)
        if user.hashed_password == encrypt_password(password, user.salt)
          user
        end
      end
    end
  
    def User.encrypt_password(password, salt)
      Digest::SHA2.hexdigest(password + "wibble" + salt)
    end
    private 
      def encrypt_password
        self.salt = make_salt if new_record?
        self.encrypted_password = encrypt(password)
      end
  
    # 'password' is a virtual attribute
    def password=(password)
      @password =password
      if password.present?
        generate_salt
        self.hashed_password =self.class.encrypt_password(password, salt)
      end
    end
  
    private
  
    def password_must_be_present
      errors.add(:password, "Missing password") unless hashed_password.present?
    end
  
    def generate_salt
      self.salt = self.object_id.to_s + rand.to_s
    end
  
  end
  </code></pre>