Created
June 21, 2015 10:49
-
-
Save dangjlin/9d5c3c2172a317d3da2f to your computer and use it in GitHub Desktop.
This file contains 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
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