Created
October 27, 2011 16:29
-
-
Save solnic/1320054 to your computer and use it in GitHub Desktop.
Virtus + DataMapper Validations
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
# this uses upcoming dm-validations, it's not released yet | |
class User | |
include Virtus | |
include DataMapper::Validations | |
# basic info | |
attribute :email, String | |
attribute :password, String | |
attribute :password_confirmation, String | |
# contact info | |
attribute :first_name, String | |
attribute :last_name, String | |
attribute :zipcode, String | |
validates_presence_of :email, :password, :password_confirmation, :context => :basic_info | |
validates_presence_of :first_name, :last_name, :zipcode, :context => :contact_info | |
end | |
user = User.new | |
user.validate(:basic_info) | |
user.validate(:contact_info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment