1

当我尝试登录注销后创建的用户时,我不断收到上述消息...

我的用户模型是这样的,名称是显示名称

class User < ActiveRecord::Base
  attr_accessible :name, :email, :persistence_token, :password, :password_confirmation

  before_save { |user| user.email = email.downcase }

  validates :email, uniqueness: true

  acts_as_authentic do |configuration|
    configuration.session_class = Session
  end
end

我的迁移是

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :email
      t.string :name
      t.string :crypted_password
      t.string :password_salt
      t.string :persistence_token
    end
  end

  def self.down
    drop_table :sessions
  end
end

我在我的登录表单中使用:email和字段:password

4

2 回答 2

3

You should set login_field parameter as :email, because by default its :username or :login field:

class User < ActiveRecord::Base
  #...

  acts_as_authentic do |configuration|
    configuration.session_class = Session
    configuration.login_field = :email
  end
end

In User model you downcase email before save, so if you want to seach case insensitive email in DB, you should implement find_by_login_method:

class Session < Authlogic::Session::Base
  find_by_login_method :find_by_downcase_email
end  

class User < ActiveRecord::Base
  #...

  def self.find_by_downcase_email(login)
    find_by_email(login.downcase)
  end
end
于 2013-04-20T01:18:06.090 回答
3

这是旧的,但对我来说,我在将 rails 3 升级到 rails 4 应用程序时遇到了这个错误。在 UserSession 创建中,我不得不更改

@user_session = UserSession.new(params[:user_session])

@user_session = UserSession.new(user_session_params)
...
private
    def user_session_params
      params.require(:user_session).permit(:email, :password)
    end
于 2016-12-16T22:00:24.907 回答