aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/examples/amo_ap_example.rb
blob: cef718d0d4d02ea7d1704218c26469991b7c10a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$:.push "activesupport/lib"
$:.push "activemodel/lib"

require "active_model/validations"
require "active_model/deprecated_error_methods"
require "active_model/errors"
require "active_model/naming"

class Person
  include ActiveModel::Validations
  extend ActiveModel::Naming
  
  validates_presence_of :name
  
  attr_accessor :name
  def initialize(attributes = {})
    @name = attributes[:name]
  end
  
  def persist
    @persisted = true
  end
  
  def new_record?
    @persisted
  end
  
  def to_model() self end
end

person1 = Person.new
p person1.valid?
person1.errors

person2 = Person.new(:name => "matz")
p person2.valid?