Follow-up to last 2 commits on Scopes/Class Methods docs

[skip ci]
This commit is contained in:
Jon Atack 2014-09-11 00:46:25 +02:00
parent 560168eb21
commit 08fcc36615
1 changed files with 5 additions and 6 deletions

View File

@ -402,14 +402,13 @@ values, or for given values if the scope accepts a value:
```ruby
class Employee < ActiveRecord::Base
scope :active, -> { where(active: true) }
scope :active, ->{ where(active: true) }
scope :salary_gt, ->(amount) { where('salary > ?', amount) }
def self.hired_since(input_string)
where('start_date >= ?', input_string.to_date)
end
# Scopes are just syntactical sugar for class methods, which may also be used:
def self.salary_gt(amount)
where('salary > ?', amount)
def self.hired_since(date)
where('start_date >= ?', date)
end
private