我正在学习如何使用设计宝石,我遇到了一些问题,我正在尝试使用'login'参数登录 . 但是我的应用程序不会更新用户登录 . 不是通过表格甚至通过控制台 .
在控制台中它只是选择登录,它实际上不会更新它:
current_sign_in_ip:nil,last_sign_in_ip:nil,created_at:“2016-03-03 15:31:55”,updated_at:“2016-03-03 15:34:21”,提供者:nil,uid:nil,login:nil > 2.2.1:036> u.login =>“stormviper”2.2.1:037> u.save! (0.1ms)开始交易用户存在(0.2ms)SELECT 1 AS一个FROM“users”WHERE(LOWER(“users” . “login”)= LOWER('stormviper')AND“users” . “id”!= 4 )LIMIT 1(0.1ms)commit transaction => true
然后在运行之后,它甚至没有更新用户的登录,我对application_controller进行了一些更改,我认为这个问题都是错的,但我不知道:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate_user!, if: :devise_controller?
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:login, :email, :password, :password_confirmation, :remember_me) }
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :password, :remember_me) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:login, :email, :password, :password_confirmation, :current_password) }
end
end
我还对user.rb做了一些更改:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
attr_accessor :login
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:authentication_keys => [:login]
validates :login,
:presence => true,
:uniqueness => {
:case_sensitive => false
}
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions.to_h).where(["lower(login) = :value OR lower(login) = :value", { :value => login.downcase }]).first
elsif conditions.has_key?(:login) || conditions.has_key?(:login)
where(conditions.to_h).first
end
end
我该如何解决这个问题?谢谢
1 回答
如果你想添加'login'参数,你可以简单地覆盖设计注册控制器并定义它