Committing documentation about automatic scopes feature.
This commit is contained in:
parent
13e7090d40
commit
699fbb7eab
31
README.md
31
README.md
|
@ -215,6 +215,37 @@ class Job < ActiveRecord::Base
|
||||||
end
|
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
|
### Transaction support
|
||||||
|
|
||||||
Since version *3.0.13* AASM supports ActiveRecord transactions. So whenever a transition
|
Since version *3.0.13* AASM supports ActiveRecord transactions. So whenever a transition
|
||||||
|
|
Loading…
Reference in New Issue