Last active
September 2, 2021 14:18
-
-
Save vilusa/1b9270fb57aeb61c51dec0cbd1673804 to your computer and use it in GitHub Desktop.
Uniq user name as clean non ascii characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first_and_last_name = "#{first_name}#{last_name}".downcase | |
first_and_last_name.gsub!("ğ", "g") | |
first_and_last_name.gsub!("ı", "i") | |
first_and_last_name.gsub!("ş", "s") | |
first_and_last_name.gsub!("ü", "u") | |
first_and_last_name.gsub!("ö", "o") | |
first_and_last_name.gsub!("ç", "c") | |
first_and_last_name.gsub!(/[^0-9A-Za-z]/, '') | |
index = 0 | |
unique_user_name = loop do | |
break first_and_last_name unless User.exists?(username: first_and_last_name) | |
index += 1 | |
first_and_last_name = "#{first_and_last_name}#{index}" | |
end | |
self.username = unique_user_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment