1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activemodel/examples/validations.rb

30 lines
427 B
Ruby
Raw Normal View History

2009-09-14 15:54:43 -04:00
require 'active_model'
class Person
2009-07-21 01:56:27 -04:00
include ActiveModel::Conversion
include ActiveModel::Validations
2009-07-21 01:56:27 -04:00
validates_presence_of :name
2009-07-21 01:56:27 -04:00
attr_accessor :name
2009-07-21 01:56:27 -04:00
def initialize(attributes = {})
@name = attributes[:name]
end
2009-07-21 01:56:27 -04:00
def persist
@persisted = true
end
2009-07-21 01:56:27 -04:00
def persisted?
@persisted
end
end
person1 = Person.new
p person1.valid?
person1.errors
person2 = Person.new(:name => "matz")
2009-07-21 01:56:27 -04:00
p person2.valid?