我跟随Devise's instructions for using usernames in addition to emails登录。除了人们可以使用重复的用户名进行注册之外,它的效果很好。如果有人尝试使用重复的电子邮件地址进行注册,则会在注册页面上向他们显示此错误消息:
1个错误禁止该用户被保存:
Email has already been taken
我希望用户名非常相似。我该如何实施?
请注意,您可能希望使用户名唯一,但也不区分大小写,因此不会同时使用用户名和用户名:
class User < ApplicationRecord
validates :username, presence: true, uniqueness: { case_sensitive: false }
# Rest of user model
end
从Devise wiki开始。