ActsAsAuthentic具有如下配置选项:
acts_as_authentic do |config|
config.merge_validates_length_of_password_field_options :within => 4..40
config.merge_validates_confirmation_of_password_field_options :within => 4..40
end
不幸的是,RestfulAuthentication 没有这些配置选项。正确的解决方案是分叉RestfulAuthentication项目并添加它们。
同时,你可以猴子补丁Authentication::ByPassword.included
:
# in app/models/user.rb:
Authentication::ByPassword.class_eval do
def self.included(base)
recipient.extend(ModelClassMethods)
recipient.class_eval do
include ModelInstanceMethods
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :password, :if => :password_required?
validates_presence_of :password_confirmation, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
validates_length_of :password, :within => 4..40, :if => :password_required?
before_save :encrypt_password
end
end
end