如何从唯一ID或字符串在Rails3中创建人类可读的用户名?

时间:2021-12-17 20:34:40

My users submit an email and our Oauth provider generates a unique ID. I want to generate a human-friendly username/slug for the users so they don't have to write one.

我的用户提交了一个电子邮件,我们的Oauth提供商生成一个唯一的ID。我想为用户生成一个友好的用户名/slug,这样他们就不用写了。

It's so that they can provide the URL as a linkage to other people. It may also be because we may introduce a "confidential" feature that hides identity but exposes this unique, human-friendly username that is generated for them.

这样他们就可以把URL作为链接提供给其他人。这也可能是因为我们可能引入了一个“机密”特性,它隐藏了身份,但暴露了为他们生成的这个独特的、友好的用户名。

How do I do that?

我该怎么做呢?

2 个解决方案

#1


1  

Just take the portion of their e-mail before the @ and append a number onto the end of it's already been taken. Given them an option to change it.

只要把他们的电子邮件的一部分在@之前,并在它的末尾加上一个数字就行了。给他们一个改变的选择。

#2


0  

I'd recommend to make a list of pronounceable syllables and pick 2-4 of them randomly.

我建议把可发音的音节列出来,随机挑出2-4个。

The syllables might be:

音节的可能是:

  1. Make a list of phonetic consonants (b,c,ch,d,t,th,...) and all phonetic vowels (a,o,oo,ou,ea,y,...) and generate all combinations consonant-vowel.
  2. 列出语音辅音(b、c、ch、d、t、th、……)和所有语音元音(a、o、oo、ou、ea、y、……),并生成所有辅音元音组合。
  3. Add combinations of two and more consonants, such as "pro", "bla", ...
  4. 添加两个或更多辅音的组合,如“pro”、“bla”、……

I'm not so sure about English but this works very well in my language.

我对英语不是很确定,但这在我的语言中很管用。

#1


1  

Just take the portion of their e-mail before the @ and append a number onto the end of it's already been taken. Given them an option to change it.

只要把他们的电子邮件的一部分在@之前,并在它的末尾加上一个数字就行了。给他们一个改变的选择。

#2


0  

I'd recommend to make a list of pronounceable syllables and pick 2-4 of them randomly.

我建议把可发音的音节列出来,随机挑出2-4个。

The syllables might be:

音节的可能是:

  1. Make a list of phonetic consonants (b,c,ch,d,t,th,...) and all phonetic vowels (a,o,oo,ou,ea,y,...) and generate all combinations consonant-vowel.
  2. 列出语音辅音(b、c、ch、d、t、th、……)和所有语音元音(a、o、oo、ou、ea、y、……),并生成所有辅音元音组合。
  3. Add combinations of two and more consonants, such as "pro", "bla", ...
  4. 添加两个或更多辅音的组合,如“pro”、“bla”、……

I'm not so sure about English but this works very well in my language.

我对英语不是很确定,但这在我的语言中很管用。