首页
学习
活动
专区
圈层
工具
发布

设计
EN

Stack Overflow用户
提问于 2016-03-03 15:37:30
回答 1查看 54关注 0票数 0

我正在学习如何使用设计创业板,我遇到了一些问题,我试图使用‘登录’参数登录。不过,我的应用程序不会更新用户登录。不是通过表单,甚至不是通过控制台。

在控制台中,它只选择登录,实际上并不更新它:

current_sign_in_ip: 0,last_sign_in_ip: 0,created_at:"2016-03-03 15:31:55",updated_at:"2016-03-03 15:34:21",提供者:0,uid: 0,登录: nil> 2.2.1 :036 > u.login =>“风暴毒蛇”2.2.1 :037 > u.save! (0.1ms)开始事务用户存在(0.2ms)从“用户”(较低(“用户”.“登录”)=较低(‘stormviper’)和“用户”中选择1作为一个.“id”= 4)限制1 (0.1ms)提交事务=> true

运行之后,它甚至不更新用户的登录,我对application_controller做了一些修改,我认为这个问题是错误的,但我不知道:

代码语言:javascript
复制
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做了一些修改:

代码语言:javascript
复制
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

我该怎么解决这个问题?谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-03-03 15:59:26

如果要添加“登录”参数,可以简单地重写、设计注册控制器并定义以下内容

代码语言:javascript
复制
def configure_sign_up_params
   params.require(:user).permit( :email, :password, :password_confirmation, :login )
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35776476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档