diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-07-21 11:27:23 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-07-21 11:27:23 -0300 |
commit | f32c3709830eb8d9f68a59c94f6791621c2b52ac (patch) | |
tree | b34cf0b9321dfd40b795cc761b158be4cbde48f6 /activemodel/examples/validations.rb | |
parent | 9a28bd787660b08aae36155066e61d3608d0b4dd (diff) | |
parent | 9d7aae710384fb5f04129c35b86c5ea5fb9d83a9 (diff) | |
download | rails-f32c3709830eb8d9f68a59c94f6791621c2b52ac.tar.gz rails-f32c3709830eb8d9f68a59c94f6791621c2b52ac.tar.bz2 rails-f32c3709830eb8d9f68a59c94f6791621c2b52ac.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activemodel/examples/validations.rb')
-rw-r--r-- | activemodel/examples/validations.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/activemodel/examples/validations.rb b/activemodel/examples/validations.rb new file mode 100644 index 0000000000..3f8311ff96 --- /dev/null +++ b/activemodel/examples/validations.rb @@ -0,0 +1,29 @@ +require 'activemodel' + +class Person + include ActiveModel::Conversion + include ActiveModel::Validations + + validates_presence_of :name + + attr_accessor :name + + def initialize(attributes = {}) + @name = attributes[:name] + end + + def persist + @persisted = true + end + + def new_record? + @persisted + end +end + +person1 = Person.new +p person1.valid? +person1.errors + +person2 = Person.new(:name => "matz") +p person2.valid? |