ruby-on-rails – 在Devise中保留大写字母不区分大小写的名称
使用名称作为键,我们如何在注册时通过忽略大小写来验证名称,同时在显示时仍然记住案例?
在config / initializers / devise.rb中,设置config.case_insensitive_keys = [:name]似乎在注册之前将整个名称小写. 例如:一些家伙自称为TheFourthMusketeer. >观点将显示TheFourthMusketeer,而不是第四个观察者 解决方法
您可能尝试的是不设置:name作为不区分大小写,这将在数据库中正确保存区分大小写的名称:
config.case_insensitive_keys = [] 然后,覆盖User上的find_first_by_auth_conditions类方法,以按名称查找用户.请注意,此代码会因数据库而异(以下是使用Postgres): def self.find_first_by_auth_conditions(warden_conditions) conditions = warden_conditions.dup if login = conditions.delete(:login) where(conditions).where("lower(name) = ?",login.downcase).first else where(conditions).first end end 这样做,User.find_for_authentication(登录:’thefourthmusketeer’)将正确返回名为“TheFourthMusketeer”的记录. 有关覆盖此方法的说明,请参见https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 第27章《解释器模式》
- VB.net check whether a file is opened or not
- 免安装oracle客户端使用pl sql连接oracle
- ruby-on-rails – 为Ruby on Rails应用程序重新启
- postgresql – 涉及外键约束的死锁
- NAND FLASH学习笔记之MTD下nand flash驱动(二)
- Type cannot use 'try' with exceptions
- c# – 在预定义的时间有效运行数十万个函数
- c# – 从具体化的“System.DateTime”类型到“Sy
- NAND flash和NOR flash的区别详解