Skip to content

Instantly share code, notes, and snippets.

@murdoch
Created October 24, 2011 00:35
Show Gist options
  • Save murdoch/1308130 to your computer and use it in GitHub Desktop.
Save murdoch/1308130 to your computer and use it in GitHub Desktop.
has secure password memo
# some notes on using has_secure_password
class User < ActiveRecord::Base
has_secure_password
attr_accessible :login_name, :password, :password_confirmation
# secure_password.rb already checks for presence of :password_digest
# so we can assume that a password is present if that validation passes
# and thus, we don't need to explicitly check for presence of password
validates :password,
:length => { :minimum => 6 }, :if => :password_digest_changed?
# secure_password.rb also checks for confirmation of :password
# but we also have to check for presence of :password_confirmation
validates :password_confirmation,
:presence=>true, :if => :password_digest_changed?
___
# In `config/locales/en.yml` make sure that errors on
# the password_digest field refer to "Password" as it's more human friendly
en:
hello: "Hello world"
activerecord:
attributes:
user:
password_digest: "Password"
@Sohair63
Copy link

Sohair63 commented Nov 1, 2016

still having Validation failed: Password confirmation can't be blank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment