Rails /设计更改用户名的最小长度

时间:2011-01-06 20:47:30

标签: ruby-on-rails authentication authlogic

Rails 3.0 Authlogic 2.1.6

使用用户名(而不是电子邮件)进行身份验证。

Authlogic要求用户名至少为3个字符。

如何说服Authologic允许使用2个字符的用户名?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以通过将以下代码添加到models / user.rb来覆盖authlogic默认用户名长度

class User < ActiveRecord::Base

  acts_as_authentic do |c|
    c.merge_validates_length_of_login_field_options :within => 4..100
  end

  #....

end

这假设您的用户模型名为User