title: Custom user authentication on Rails 4
body: <p>I'm trying to learn and use my own user model and authentication with Ruby on Rails 4.0, but most tutorials (if not all) seem to be outdated with this recent update. No method described on any of them works. I'm absolutely clueless, this is my User model:</p>
  
  <pre><code>class User
    include Mongoid::Document
    field :login, type: String
    field :hash, type: String
    field :salt, type: String
    field :email, type: String
    field :name, type: String
  
    before_save :hash_password
  
    validate :login, presence: true, uniqueness: true, length: { in: 4..24 }
    validate :password, presence: true, confirmation: true, length: { in: 8..32 }
    validate :email, presence: true
    validate :name, presence: true
  
    def hash_password
      if password.present?
        self.salt = BCrypt::Engine.generate_salt
        self.hash = BCrypt::Engine.hash_secret(password, salt)
      end
    end
  end
  </code></pre>
  
  <p>And the controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    def create
      @user = User.new(user_params)
      if @user.save
        redirect_to @user
      else
        render 'new'
      end
    end
  
    def new
      @user = User.new
    end
  
    private
      def user_params
        params.require(:user).permit(:login, :password, :password_confirmation, :email, :name)
      end
  end
  </code></pre>
  
  <p>I then get an <code>UnknownAttribute</code> error when I save the user. What am I missing? What fields are wrong?</p>