提交 108545a9 编写于 作者: J Joshua Peek

Clean up validation example

上级 574323df
$:.push "activesupport/lib"
$:.push "activemodel/lib"
require "active_model/validations"
require "active_model/deprecated_error_methods"
require "active_model/errors"
require "active_model/naming"
require 'activemodel'
class Person
include ActiveModel::Conversion
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
......@@ -33,4 +26,4 @@ def to_model() self end
person1.errors
person2 = Person.new(:name => "matz")
p person2.valid?
\ No newline at end of file
p person2.valid?
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册