Using a name as key, how do we validate the name when registering by ignoring case while still remembering the case when displaying?
In config/initializers/devise.rb, setting config.case_insensitive_keys = [ :name ] seems to lowercase the entire name before registering.
Example: some dude names himself TheFourthMusketeer.
- The views will display TheFourthMusketeer, not thefourthmusketeer
- No new user can register under, say, tHEfourthMUSKETEER
What you might try is to not set
:nameas case insensitive, which will properly save the case-sensitive name in the database:Then, override the
find_first_by_auth_conditionsclass method on User to find the user by their name. Note that this code will vary depending on the database (below is using Postgres):Doing this, a
User.find_for_authentication(login: 'thefourthmusketeer')will properly return the record with anameof “TheFourthMusketeer”.See https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address for an explanation of overriding this method.