Committing documentation about automatic scopes feature.

This commit is contained in:
Johnny Shields 2013-01-07 07:42:05 +09:00
parent 13e7090d40
commit 699fbb7eab
1 changed files with 31 additions and 0 deletions

View File

@ -215,6 +215,37 @@ class Job < ActiveRecord::Base
end
```
### Automatic Scopes
AASM will automatically create scope methods for each state in the model.
```ruby
class Job < ActiveRecord::Base
include AASM
aasm do
state :sleeping, :initial => true
state :running
state :cleaning
end
def sleeping
"This method name is in already use"
end
end
```
```ruby
class JobsController < ApplicationController
def index
@running_jobs = jobs.running
@recent_cleaning_jobs = jobs.cleaning.where('created_at >= ?', 3.days.ago)
# @sleeping_jobs = jobs.sleeping #=> "This method name is in already use"
end
end
```
### Transaction support
Since version *3.0.13* AASM supports ActiveRecord transactions. So whenever a transition