提交 344a6953 编写于 作者: E eparreno

AR validations: update sections 2.4 and 17.1

上级 785caba8
......@@ -115,17 +115,17 @@ end
>> p = Person.new
=> #<Person id: nil, name: nil>
>> p.errors
=> #<ActiveRecord::Errors..., @errors={}>
=> {}
>> p.valid?
=> false
>> p.errors
=> #<ActiveRecord::Errors..., @errors={"name"=>["can't be blank"]}>
=> {:name=>["can't be blank"]}
>> p = Person.create
=> #<Person id: nil, name: nil>
>> p.errors
=> #<ActiveRecord::Errors..., @errors={"name"=>["can't be blank"]}>
=> {:name=>["can't be blank"]}
>> p.save
=> false
......@@ -1112,6 +1112,10 @@ h4. Creating Observers
For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we could create an observer to contain this functionality.
<shell>
rails generate observer User
</shell>
<ruby>
class UserObserver < ActiveRecord::Observer
def after_create(model)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册