mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add CHANGELOG entry and update the guide
This commit is contained in:
parent
60c65ca8df
commit
f31ea4df3a
2 changed files with 23 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
|||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* Allow before and after validations to take an array of lifecycle events
|
||||
|
||||
*John Foley*
|
||||
|
||||
* Support for specifying transaction isolation level
|
||||
|
||||
If your database supports setting the isolation level for a transaction, you can set
|
||||
|
|
|
@ -995,6 +995,25 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
```
|
||||
|
||||
Callbacks can also be registered to only fire on certain lifecycle events:
|
||||
<ruby>
|
||||
class User < ActiveRecord::Base
|
||||
before_validation :normalize_name, :on => :create
|
||||
|
||||
# :on takes an array as well
|
||||
after_validation :set_location, :on => [ :create, :update ]
|
||||
|
||||
protected
|
||||
def normalize_name
|
||||
self.name = self.name.downcase.titleize
|
||||
end
|
||||
|
||||
def set_location
|
||||
self.location = LocationService.query(self)
|
||||
end
|
||||
end
|
||||
</ruby>
|
||||
|
||||
It is considered good practice to declare callback methods as protected or private. If left public, they can be called from outside of the model and violate the principle of object encapsulation.
|
||||
|
||||
Available Callbacks
|
||||
|
|
Loading…
Reference in a new issue