From 108545a9d69215aa0205f7e6b52eb1573443d404 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 21 Jul 2009 00:56:27 -0500 Subject: Clean up validation example --- activemodel/examples/validations.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 activemodel/examples/validations.rb (limited to 'activemodel/examples/validations.rb') 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? -- cgit v1.2.3