[英]Ruby on rails devise
I am learning how to use the devise gem and I have run into a few issues, I am trying to use the 'login' parameter to login. 我正在学习如何使用devise gem,但遇到了一些问题,我试图使用'login'参数进行登录。 However my app will not update the users login.
但是我的应用程序不会更新用户登录信息。 Not through forms or even through the console.
不能通过表单,甚至不能通过控制台。
In the console it just SELECTs the login, it doesn't actually update it: 在控制台中,它只是选择登录名,实际上并没有更新它:
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", provider: nil, uid: nil, login: nil>
current_sign_in_ip:无,last_sign_in_ip:无,created_at:“ 2016-03-03 15:31:55”,updated_at:“ 2016-03-03 15:34:21”,提供者:nil,uid:nil,登录名:nil>
2.2.1 :036 > u.login => "stormviper" 2.2.1 :037 > u.save!
2.2.1:036> u.login =>“ stormviper” 2.2.1:037> u.save!
(0.1ms) begin transaction User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."login") = LOWER('stormviper') AND "users"."id" != 4) LIMIT 1 (0.1ms) commit transaction => true
(0.1毫秒)开始事务用户存在(0.2毫秒)从“用户”位置选择一个1(LOWER(“ users”。“ login”)= LOWER('stormviper')AND“ users”。“ id”!= 4 )LIMIT 1(0.1ms)commit transaction => true
And then after this is run, it doesn't even update the User's login, I have made some changes to the application_controller which I believe the issue to be all wrong, but I don't know: 然后运行此命令后,它甚至不更新用户的登录名,我对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
I have also made a few changes to the user.rb: 我还对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
How would I go about solving this? 我将如何解决这个问题? Thanks
谢谢
if you want to add 'login' parameter you can simply override devise registration controller and define this 如果您想添加“登录”参数,则可以简单地覆盖devise注册控制器并定义它
def configure_sign_up_params
params.require(:user).permit( :email, :password, :password_confirmation, :login )
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.