在你的model中加入
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
if signin = conditions.delete(:signin)
where(conditions.to_h).where(["lower(username) = :value OR lower(mobile) = :value", { :value => signin.downcase }]).first
elsif conditions.has_key?(:username)|| conditions.has_key?(:mobile)
where(conditions.to_h).first
end
end
attr_accessor :signin
在application_controller.rb中加入
before_action :configure_permitted_parametersod_name, if: :devise_controller? def configure_permitted_parametersod_name
devise_parameter_sanitizer.permit(:sign_in) {|u| u.permit(:signin,:username, :mobile, :password, :remember_me)}
devise_parameter_sanitizer.permit(:sign_up) {|u|
u.permit(:signin,:username, :mobile, :password, :password_confirmation)}
end
最后更改devise.rb
config.authentication_keys = [:signin]