mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Add example code to Scopes docs in README
[skip ci]
This commit is contained in:
parent
620f53eb29
commit
6b6f232600
1 changed files with 16 additions and 0 deletions
16
README.md
16
README.md
|
@ -401,6 +401,22 @@ methods (e.g. scopes) are ignored. Scopes will be applied for matching `true`
|
|||
values, or for given values if the scope accepts a value:
|
||||
|
||||
```ruby
|
||||
class Employee < ActiveRecord::Base
|
||||
scope :active, -> { where(active: true) }
|
||||
|
||||
def self.hired_since(date = Date.current)
|
||||
where('start_date >= ?', date)
|
||||
end
|
||||
|
||||
def self.salary_gt(amount)
|
||||
where('salary > ?', amount)
|
||||
end
|
||||
|
||||
private
|
||||
def self.ransackable_scopes(auth_object = nil)
|
||||
%i(active hired_since salary_gt)
|
||||
end
|
||||
|
||||
Employee.search({ active: true, hired_since: '2013-01-01' })
|
||||
|
||||
Employee.search({ salary_gt: 100_000 }, { auth_object: current_user })
|
||||
|
|
Loading…
Reference in a new issue