Created
July 29, 2012 19:07
-
-
Save bnadlerjr/3201217 to your computer and use it in GitHub Desktop.
Validator Example
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
| require 'validus' | |
| class PersonValidator | |
| include Validus | |
| def initialize(attributes) | |
| @attributes = attributes | |
| end | |
| def validate | |
| errors.add(:name, 'cannot be blank') if @attributes[:name] == '' | |
| end | |
| end | |
| validator = PersonValidator.new({ :name => 'John' }) | |
| validator.valid? # => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment