mirror of
https://github.com/activerecord-hackery/ransack.git
synced 2022-11-09 13:47:45 -05:00
Revert "Update README to point out 2 caveats with scopes and"
This reverts commit cde3e0e6f2
.
This commit is contained in:
parent
cde3e0e6f2
commit
3808340117
4 changed files with 10 additions and 23 deletions
16
README.md
16
README.md
|
@ -42,18 +42,12 @@ gem 'ransack', github: 'activerecord-hackery/ransack'
|
||||||
|
|
||||||
The other branches (`rails-4`, `rails-4.1`, and `rails-4.2`) were each used for
|
The other branches (`rails-4`, `rails-4.1`, and `rails-4.2`) were each used for
|
||||||
developing and running Ransack with the latest upcoming version of Rails at the
|
developing and running Ransack with the latest upcoming version of Rails at the
|
||||||
time. They are smaller and possibly slightly faster because they do not have to
|
time. They are lighter and somewhat faster-running because they do not have to
|
||||||
support previous versions of Rails and Active Record. Once support for that
|
support previous versions of Rails and Active Record. Once support for that
|
||||||
Rails version is merged from the branch into Ransack master, the branch is no
|
Rails version is merged from the branch into Ransack master, the branch is no
|
||||||
longer actively maintained -- unless the open source community submits pull
|
longer actively maintained -- unless the open source community submits pull
|
||||||
requests to maintain them. You are welcome to do so!
|
requests to maintain them. You are welcome to do so!
|
||||||
|
|
||||||
To use one of the branches, for example the `rails-4.1` branch:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
gem 'ransack', github: 'activerecord-hackery/ransack', branch: 'rails-4.1'
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Ransack can be used in one of two modes, simple or advanced.
|
Ransack can be used in one of two modes, simple or advanced.
|
||||||
|
@ -413,7 +407,7 @@ scope accepts a value:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Employee < ActiveRecord::Base
|
class Employee < ActiveRecord::Base
|
||||||
scope :active, ->(boolean = true) { where(active: boolean) }
|
scope :active, ->(boolean = true) { (where active: boolean) }
|
||||||
scope :salary_gt, ->(amount) { where('salary > ?', amount) }
|
scope :salary_gt, ->(amount) { where('salary > ?', amount) }
|
||||||
|
|
||||||
# Scopes are just syntactical sugar for class methods, which may also be used:
|
# Scopes are just syntactical sugar for class methods, which may also be used:
|
||||||
|
@ -440,12 +434,6 @@ Employee.search({ active: true, hired_since: '2013-01-01' })
|
||||||
Employee.search({ salary_gt: 100_000 }, { auth_object: current_user })
|
Employee.search({ salary_gt: 100_000 }, { auth_object: current_user })
|
||||||
```
|
```
|
||||||
|
|
||||||
Scopes are a recent addition to Ransack and currently have 2 caveats: First, if
|
|
||||||
you are using a scope with associations, for now you'll need to define the
|
|
||||||
scope in the parent table model, not in the child model. Second, scopes on
|
|
||||||
arrays of values are not yet working correctly; in this case, it may be better
|
|
||||||
to use Ransackers instead.
|
|
||||||
|
|
||||||
### Grouping queries by OR instead of AND
|
### Grouping queries by OR instead of AND
|
||||||
|
|
||||||
The default `AND` grouping can be changed to `OR` by adding `m: 'or'` to the
|
The default `AND` grouping can be changed to `OR` by adding `m: 'or'` to the
|
||||||
|
|
|
@ -96,9 +96,8 @@ module Ransack
|
||||||
css = ['sort_link', current_dir].compact.join(' ')
|
css = ['sort_link', current_dir].compact.join(' ')
|
||||||
html_options[:class] = [css, html_options[:class]].compact.join(' ')
|
html_options[:class] = [css, html_options[:class]].compact.join(' ')
|
||||||
query_hash = {}
|
query_hash = {}
|
||||||
query_hash[search.context.search_key] = search_params.merge(
|
query_hash[search.context.search_key] = search_params
|
||||||
:s => "#{attr_name} #{new_dir}"
|
.merge(:s => "#{attr_name} #{new_dir}")
|
||||||
)
|
|
||||||
options.merge!(query_hash)
|
options.merge!(query_hash)
|
||||||
options_for_url = params.merge options
|
options_for_url = params.merge options
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module Ransack
|
module Ransack
|
||||||
VERSION = "1.4.2"
|
VERSION = "1.4.1"
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,10 +71,10 @@ module Ransack
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#sort_link through association table defined as a symbol' do
|
describe '#sort_link desc through association table defined as a symbol' do
|
||||||
subject { @controller.view_context
|
subject { @controller.view_context
|
||||||
.sort_link(
|
.sort_link(
|
||||||
Person.search({ :sorts => 'comments_body' }),
|
Person.search({ :sorts => ['comments_body asc'] }),
|
||||||
:comments_body, :controller => 'people'
|
:comments_body, :controller => 'people'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,8 @@ module Ransack
|
||||||
describe '#sort_link through association table defined as a string' do
|
describe '#sort_link through association table defined as a string' do
|
||||||
subject { @controller.view_context
|
subject { @controller.view_context
|
||||||
.sort_link(
|
.sort_link(
|
||||||
Person.search({ :sorts => 'comments.body desc' }),
|
Person.search({ :sorts => ['comments.body desc'] }),
|
||||||
:comments_body, :controller => 'people'
|
'comments.body', :controller => 'people'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
it {
|
it {
|
||||||
|
@ -108,7 +108,7 @@ module Ransack
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
it { should match /sort_link desc/ }
|
it { should match /sort_link desc/ }
|
||||||
it { should match /Body ▼/ }
|
it { should match /Comments.body ▼/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#sort_link works even if search params are a blank string' do
|
describe '#sort_link works even if search params are a blank string' do
|
||||||
|
|
Loading…
Reference in a new issue