Skip to content

Instantly share code, notes, and snippets.

@jparker
Created November 12, 2012 23:05
Show Gist options
  • Save jparker/4062658 to your computer and use it in GitHub Desktop.
Save jparker/4062658 to your computer and use it in GitHub Desktop.
Validate :password in addition to :password_digest
[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"]
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