Permalink
Browse files

Fixed Issue #2884 ActiveModel::SecurePassword code / rdoc conflict; a…

…n elucidated explanation has been provided and ActiveModel en-locale updated to present a less confusing attribute name for 'password_digest' in form errors due to "has_secure_password"
  • Loading branch information...
1 parent 625cb12 commit ddbea9474e20a40e80110944c1e3493ba0efe572 @bsodmike bsodmike committed Mar 11, 2012
Showing with 17 additions and 0 deletions.
  1. +4 −0 activemodel/lib/active_model/locale/en.yml
  2. +13 −0 activemodel/lib/active_model/secure_password.rb
@@ -1,4 +1,8 @@
en:
+ attributes:
+ # Prevent confusion in form errors due to 'has_secure_password'
+ password_digest: "Password"
+
errors:
# The default format to use in full error messages.
format: "%{attribute} %{message}"
@@ -10,6 +10,19 @@ module ClassMethods
# a "password_confirmation" attribute) are automatically added.
# You can add more validations by hand if need be.
#
+ # Note: the implementation of <tt>has_secure_password</tt> enforces presence validation
+ # on the <tt>:password_digest</tt> attribute rather than on <tt>:password</tt>, which is
+ # in fact a virtual reader attribute. However, <tt>validates_confirmation_of</tt> ensures
+ # an indirect means of presence validation of <tt>:password</tt> if the
+ # <tt>:password_confirmation</tt> attribute is not nil.
+ #
+ # You may want to add presence validation on <tt>:password</tt> for the benefit of your forms
+ #
+ # class User < ActiveRecord::Base
+ # has_secure_password
+ # validates :password, :presence => { :on => :create }
+ # end
+ #
# You need to add bcrypt-ruby (~> 3.0.0) to Gemfile to use has_secure_password:
#
# gem 'bcrypt-ruby', '~> 3.0.0'

0 comments on commit ddbea94

Please sign in to comment.