Skip to content

Instantly share code, notes, and snippets.

@masawada
Created September 7, 2013 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masawada/6477170 to your computer and use it in GitHub Desktop.
Save masawada/6477170 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_secure_password
...
validates :password,
:length => { :minimum => 8, :if => :validate_password? },
:confirmation => { :if => :validate_password? }
private
def validate_password?
password.present? || password_confirmation.present?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment