Skip to content

Instantly share code, notes, and snippets.

@vilusa
Last active September 2, 2021 14:18
Show Gist options
  • Save vilusa/1b9270fb57aeb61c51dec0cbd1673804 to your computer and use it in GitHub Desktop.
Save vilusa/1b9270fb57aeb61c51dec0cbd1673804 to your computer and use it in GitHub Desktop.
Uniq user name as clean non ascii 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