Skip to content

Instantly share code, notes, and snippets.

@dangjlin
Created June 21, 2015 10: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 dangjlin/9d5c3c2172a317d3da2f to your computer and use it in GitHub Desktop.
Save dangjlin/9d5c3c2172a317d3da2f to your computer and use it in GitHub Desktop.
require 'active_model'
class User
include ActiveModel::Validations
attr_accessor :password
validate do
errors.add(:base, "Don't let dad choose the password.") if password == '1234'
end
end
user = User.new
user.password = '12345'
user.valid? # => true
user.password = '1234'
user.valid? # => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment