0

Ive been searching and cant seem to find a question that answers this. Im pretty new to devise. Ive added a username column to my users model, and added the username field to the registration form.

But how can I require that the username field be filled out upon registration? Also check thats its unique?

4

1 回答 1

1

如果您希望通过用户名(而不是设计默认电子邮件)登录,Ryan Bates 在他的RailsCasts 第 210 集:自定义设计中介绍了您,请参阅自定义登录要求的最后一节。

但是,如果用户名是 User 表中的附加字段,请将其添加为 attr_accessible 并编写正常的 rails 验证。例子:

validates :username, :presence => true, :uniqueness => true

它可能还需要对视图进行一些自定义以标准化验证错误显示。

于 2012-10-09T21:41:09.063 回答