用户名最大长度在Devise 3.2中

时间:2013-11-16 01:39:07

标签: ruby-on-rails ruby-on-rails-3 devise ruby-on-rails-4

当我尝试保存新密码时,出现用户用户名太长的错误(我正在使用username mechanism for Devise with Rails 3.2.x here)。如何增加用户名的长度?我在devise.rb中没有看到任何相关内容。

irb(main):002:0> u.password='resetpass'
=> "resetpass"
irb(main):003:0> u.password_confirmation='resetpass'
=> "resetpass"
irb(main):005:0> u.save!
   (0.9ms)  BEGIN
  User Exists (1.6ms)  SELECT 1 AS one FROM "users" WHERE (LOWER("users"."username") = LOWER('exterminator5000') AND "users"."id" != 128) LIMIT 1
   (0.7ms)  ROLLBACK
ActiveRecord::RecordInvalid: Validation failed: Username must have at most 15 characters

2 个答案:

答案 0 :(得分:0)

似乎问题出在您的User模型中。看看这个http://edgeguides.rubyonrails.org/active_record_validations.html#length。您应该更改此字段的length验证。

答案 1 :(得分:0)

 validates :username, :length => { :maximum => 50 }

Add您的User Model中的这行代码会对至少50 characters进行验证。