mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
AR validations: update sections 2.4 and 17.1
This commit is contained in:
parent
785caba866
commit
344a695383
1 changed files with 7 additions and 3 deletions
|
@ -115,17 +115,17 @@ end
|
||||||
>> p = Person.new
|
>> p = Person.new
|
||||||
=> #<Person id: nil, name: nil>
|
=> #<Person id: nil, name: nil>
|
||||||
>> p.errors
|
>> p.errors
|
||||||
=> #<ActiveRecord::Errors..., @errors={}>
|
=> {}
|
||||||
|
|
||||||
>> p.valid?
|
>> p.valid?
|
||||||
=> false
|
=> false
|
||||||
>> p.errors
|
>> p.errors
|
||||||
=> #<ActiveRecord::Errors..., @errors={"name"=>["can't be blank"]}>
|
=> {:name=>["can't be blank"]}
|
||||||
|
|
||||||
>> p = Person.create
|
>> p = Person.create
|
||||||
=> #<Person id: nil, name: nil>
|
=> #<Person id: nil, name: nil>
|
||||||
>> p.errors
|
>> p.errors
|
||||||
=> #<ActiveRecord::Errors..., @errors={"name"=>["can't be blank"]}>
|
=> {:name=>["can't be blank"]}
|
||||||
|
|
||||||
>> p.save
|
>> p.save
|
||||||
=> false
|
=> 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.
|
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>
|
<ruby>
|
||||||
class UserObserver < ActiveRecord::Observer
|
class UserObserver < ActiveRecord::Observer
|
||||||
def after_create(model)
|
def after_create(model)
|
||||||
|
|
Loading…
Reference in a new issue