Created
November 12, 2012 23:05
-
-
Save jparker/4062658 to your computer and use it in GitHub Desktop.
Validate :password in addition to :password_digest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> user = User.new(password: nil, password_confirmation: nil) | |
=> #<User id: nil, username: nil, email: nil, name: nil, password_digest: nil, created_at: nil, updated_at: nil> | |
[2] pry(main)> user.valid? | |
=> false | |
[3] pry(main)> user.invalid?(:password) | |
=> true | |
[4] pry(main)> user.errors[:password] | |
=> [] | |
[5] pry(main)> user.errors[:password_confirmation] | |
=> [] | |
[6] pry(main)> user.errors[:password_digest] | |
=> ["can't be blank"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_secure_password | |
validates :password, presence: { on: :create }, length: { minimum: 8, allow_blank: true } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment