Skip to content
This repository
Browse code

Clean up validation example

  • Loading branch information...
commit 108545a9d69215aa0205f7e6b52eb1573443d404 1 parent 574323d
Joshua Peek josh authored
23 activemodel/examples/amo_ap_example.rb → activemodel/examples/validations.rb
... ... @@ -1,31 +1,24 @@
1   -$:.push "activesupport/lib"
2   -$:.push "activemodel/lib"
3   -
4   -require "active_model/validations"
5   -require "active_model/deprecated_error_methods"
6   -require "active_model/errors"
7   -require "active_model/naming"
  1 +require 'activemodel'
8 2
9 3 class Person
  4 + include ActiveModel::Conversion
10 5 include ActiveModel::Validations
11   - extend ActiveModel::Naming
12   -
  6 +
13 7 validates_presence_of :name
14   -
  8 +
15 9 attr_accessor :name
  10 +
16 11 def initialize(attributes = {})
17 12 @name = attributes[:name]
18 13 end
19   -
  14 +
20 15 def persist
21 16 @persisted = true
22 17 end
23   -
  18 +
24 19 def new_record?
25 20 @persisted
26 21 end
27   -
28   - def to_model() self end
29 22 end
30 23
31 24 person1 = Person.new
@@ -33,4 +26,4 @@ def to_model() self end
33 26 person1.errors
34 27
35 28 person2 = Person.new(:name => "matz")
36   -p person2.valid?
  29 +p person2.valid?

0 comments on commit 108545a

Please sign in to comment.
Something went wrong with that request. Please try again.