ransack 2.4.0 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/SECURITY.md +12 -0
- data/.github/workflows/cronjob.yml +105 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.github/workflows/test.yml +154 -0
- data/.rubocop.yml +44 -0
- data/CHANGELOG.md +8 -3
- data/CONTRIBUTING.md +2 -5
- data/Gemfile +4 -2
- data/README.md +95 -25
- data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
- data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
- data/docs/img/create_release.png +0 -0
- data/docs/release_process.md +20 -0
- data/lib/polyamorous/activerecord_6.2_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_6.2_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_6.2_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/polyamorous.rb +1 -1
- data/lib/ransack.rb +2 -2
- data/lib/ransack/adapters/active_record/base.rb +4 -0
- data/lib/ransack/adapters/active_record/context.rb +10 -3
- data/lib/ransack/adapters/active_record/ransack/constants.rb +1 -1
- data/lib/ransack/configuration.rb +17 -1
- data/lib/ransack/constants.rb +2 -3
- data/lib/ransack/helpers.rb +1 -1
- data/lib/ransack/helpers/form_builder.rb +3 -3
- data/lib/ransack/nodes/attribute.rb +1 -1
- data/lib/ransack/nodes/condition.rb +0 -2
- data/lib/ransack/nodes/sort.rb +1 -1
- data/lib/ransack/nodes/value.rb +1 -1
- data/lib/ransack/search.rb +2 -1
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +4 -3
- data/spec/blueprints/articles.rb +1 -1
- data/spec/blueprints/comments.rb +1 -1
- data/spec/blueprints/notes.rb +1 -1
- data/spec/blueprints/tags.rb +1 -1
- data/spec/console.rb +5 -5
- data/spec/helpers/ransack_helper.rb +1 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +6 -3
- data/spec/ransack/adapters/active_record/context_spec.rb +1 -2
- data/spec/ransack/configuration_spec.rb +10 -0
- data/spec/ransack/helpers/form_helper_spec.rb +16 -16
- data/spec/ransack/nodes/grouping_spec.rb +2 -2
- data/spec/ransack/predicate_spec.rb +1 -1
- data/spec/ransack/search_spec.rb +49 -2
- data/spec/spec_helper.rb +7 -6
- data/spec/support/schema.rb +2 -2
- metadata +16 -4
- data/.travis.yml +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7e53f2a86ba264e751c3311254c7cb4b25efdb0c876310835b6f6221ab24928
|
4
|
+
data.tar.gz: 161ca5255a24fa42c63d6afbbf38e518581189db773e7e43940b31b1b8d86850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17c4701dbf3523dfa16feae0dd0dddc8bd077237d7e695eb69664f1b9c5ab5e2fea4a59b5878fe8e607b135ea834f12284f03c42a9ce2971f2f9c9b65d347205
|
7
|
+
data.tar.gz: 4c9d09980609ffc43bc505a947781b9fcdc97efb7897c3bbc3278d8391ab219e4fdffd8a813272a3af7403eefc162fddb6f9f379b713894d3951ff2fc7a141f3
|
data/.github/FUNDING.yml
ADDED
data/.github/SECURITY.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
At the moment, only the latest major.minor release stream is supported with
|
6
|
+
security updates.
|
7
|
+
|
8
|
+
## Reporting a Vulnerability
|
9
|
+
|
10
|
+
Please use the Tidelift security contact to [report a security
|
11
|
+
vulnerability](https://tidelift.com/security). Tidelift will coordinate the fix
|
12
|
+
and disclosure.
|
@@ -0,0 +1,105 @@
|
|
1
|
+
name: cronjob
|
2
|
+
|
3
|
+
on:
|
4
|
+
schedule:
|
5
|
+
- cron: "0 0 * * *"
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
sqlite3:
|
9
|
+
runs-on: ubuntu-20.04
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby:
|
14
|
+
- 3.0.0
|
15
|
+
- 2.7.2
|
16
|
+
- 2.6.6
|
17
|
+
env:
|
18
|
+
DB: sqlite3
|
19
|
+
RAILS: main
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
- name: Install dependencies
|
27
|
+
run: bundle install
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rspec
|
30
|
+
|
31
|
+
mysql:
|
32
|
+
runs-on: ubuntu-20.04
|
33
|
+
strategy:
|
34
|
+
fail-fast: false
|
35
|
+
matrix:
|
36
|
+
ruby:
|
37
|
+
- 3.0.0
|
38
|
+
- 2.7.2
|
39
|
+
- 2.6.6
|
40
|
+
env:
|
41
|
+
DB: mysql
|
42
|
+
RAILS: main
|
43
|
+
MYSQL_USERNAME: root
|
44
|
+
MYSQL_PASSWORD: root
|
45
|
+
steps:
|
46
|
+
- uses: actions/checkout@v2
|
47
|
+
- name: Set up Ruby
|
48
|
+
uses: ruby/setup-ruby@v1
|
49
|
+
with:
|
50
|
+
ruby-version: ${{ matrix.ruby }}
|
51
|
+
- name: Startup MySQL
|
52
|
+
run: |
|
53
|
+
sudo systemctl start mysql.service
|
54
|
+
- name: Setup databases
|
55
|
+
run: |
|
56
|
+
mysql --user=root --password=root --host=127.0.0.1 -e 'create database ransack collate utf8_general_ci;';
|
57
|
+
mysql --user=root --password=root --host=127.0.0.1 -e 'use ransack;show variables like "%character%";show variables like "%collation%";';
|
58
|
+
- name: Install dependencies
|
59
|
+
run: bundle install
|
60
|
+
- name: Run tests
|
61
|
+
run: bundle exec rspec
|
62
|
+
|
63
|
+
postgres:
|
64
|
+
runs-on: ubuntu-20.04
|
65
|
+
strategy:
|
66
|
+
fail-fast: false
|
67
|
+
matrix:
|
68
|
+
ruby:
|
69
|
+
- 3.0.0
|
70
|
+
- 2.7.2
|
71
|
+
- 2.6.6
|
72
|
+
env:
|
73
|
+
DB: postgres
|
74
|
+
RAILS: main
|
75
|
+
DATABASE_USERNAME: postgres
|
76
|
+
DATABASE_PASSWORD: postgres
|
77
|
+
DATABASE_HOST: 127.0.0.1
|
78
|
+
services:
|
79
|
+
postgres:
|
80
|
+
image: postgres
|
81
|
+
ports:
|
82
|
+
- 5432:5432
|
83
|
+
env:
|
84
|
+
POSTGRES_PASSWORD: postgres
|
85
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
86
|
+
# Set health checks to wait until postgres has started
|
87
|
+
options: >-
|
88
|
+
--health-cmd pg_isready
|
89
|
+
--health-interval 10s
|
90
|
+
--health-timeout 5s
|
91
|
+
--health-retries 5
|
92
|
+
|
93
|
+
steps:
|
94
|
+
- uses: actions/checkout@v2
|
95
|
+
- name: Set up Ruby
|
96
|
+
uses: ruby/setup-ruby@v1
|
97
|
+
with:
|
98
|
+
ruby-version: ${{ matrix.ruby }}
|
99
|
+
- name: Setup databases
|
100
|
+
run: |
|
101
|
+
psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
|
102
|
+
- name: Install dependencies
|
103
|
+
run: bundle install
|
104
|
+
- name: Run tests
|
105
|
+
run: bundle exec rspec
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: rubocop
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-20.04
|
10
|
+
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: 3.0.0
|
17
|
+
- name: Install gems
|
18
|
+
run: bundle install --jobs 4 --retry 3
|
19
|
+
- name: Run RuboCop
|
20
|
+
run: bundle exec rubocop --parallel
|
@@ -0,0 +1,154 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
sqlite3:
|
9
|
+
runs-on: ubuntu-20.04
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
rails:
|
14
|
+
- v6.1.1
|
15
|
+
- v6.0.3
|
16
|
+
- 6-0-stable
|
17
|
+
- 5-2-stable
|
18
|
+
- v5.2.4
|
19
|
+
ruby:
|
20
|
+
- 3.0.0
|
21
|
+
- 2.7.2
|
22
|
+
- 2.6.6
|
23
|
+
exclude:
|
24
|
+
- rails: v5.2.4
|
25
|
+
ruby: 3.0.0
|
26
|
+
- rails: 5-2-stable
|
27
|
+
ruby: 3.0.0
|
28
|
+
env:
|
29
|
+
DB: sqlite3
|
30
|
+
RAILS: ${{ matrix.rails }}
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v2
|
33
|
+
- name: Set up Ruby
|
34
|
+
uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby }}
|
37
|
+
- name: Install dependencies
|
38
|
+
run: bundle install
|
39
|
+
- name: Run tests
|
40
|
+
run: bundle exec rspec
|
41
|
+
|
42
|
+
mysql:
|
43
|
+
runs-on: ubuntu-20.04
|
44
|
+
strategy:
|
45
|
+
fail-fast: false
|
46
|
+
matrix:
|
47
|
+
rails:
|
48
|
+
- v6.1.1
|
49
|
+
- v6.0.3
|
50
|
+
- 6-0-stable
|
51
|
+
- 5-2-stable
|
52
|
+
- v5.2.4
|
53
|
+
ruby:
|
54
|
+
- 3.0.0
|
55
|
+
- 2.7.2
|
56
|
+
- 2.6.6
|
57
|
+
exclude:
|
58
|
+
- rails: v5.2.4
|
59
|
+
ruby: 3.0.0
|
60
|
+
- rails: 5-2-stable
|
61
|
+
ruby: 3.0.0
|
62
|
+
env:
|
63
|
+
DB: mysql
|
64
|
+
RAILS: ${{ matrix.rails }}
|
65
|
+
MYSQL_USERNAME: root
|
66
|
+
MYSQL_PASSWORD: root
|
67
|
+
steps:
|
68
|
+
- uses: actions/checkout@v2
|
69
|
+
- name: Set up Ruby
|
70
|
+
uses: ruby/setup-ruby@v1
|
71
|
+
with:
|
72
|
+
ruby-version: ${{ matrix.ruby }}
|
73
|
+
- name: Startup MySQL
|
74
|
+
run: |
|
75
|
+
sudo systemctl start mysql.service
|
76
|
+
- name: Setup databases
|
77
|
+
run: |
|
78
|
+
mysql --user=root --password=root --host=127.0.0.1 -e 'create database ransack collate utf8_general_ci;';
|
79
|
+
mysql --user=root --password=root --host=127.0.0.1 -e 'use ransack;show variables like "%character%";show variables like "%collation%";';
|
80
|
+
- name: Install dependencies
|
81
|
+
run: bundle install
|
82
|
+
- name: Run tests
|
83
|
+
run: bundle exec rspec
|
84
|
+
|
85
|
+
postgres:
|
86
|
+
runs-on: ubuntu-20.04
|
87
|
+
strategy:
|
88
|
+
fail-fast: false
|
89
|
+
matrix:
|
90
|
+
rails:
|
91
|
+
- v6.1.1
|
92
|
+
- v6.0.3
|
93
|
+
- 6-0-stable
|
94
|
+
- 5-2-stable
|
95
|
+
- v5.2.4
|
96
|
+
ruby:
|
97
|
+
- 3.0.0
|
98
|
+
- 2.7.2
|
99
|
+
- 2.6.6
|
100
|
+
exclude:
|
101
|
+
- rails: v5.2.4
|
102
|
+
ruby: 3.0.0
|
103
|
+
- rails: 5-2-stable
|
104
|
+
ruby: 3.0.0
|
105
|
+
env:
|
106
|
+
DB: postgres
|
107
|
+
RAILS: ${{ matrix.rails }}
|
108
|
+
DATABASE_USERNAME: postgres
|
109
|
+
DATABASE_PASSWORD: postgres
|
110
|
+
DATABASE_HOST: 127.0.0.1
|
111
|
+
services:
|
112
|
+
postgres:
|
113
|
+
image: postgres
|
114
|
+
ports:
|
115
|
+
- 5432:5432
|
116
|
+
env:
|
117
|
+
POSTGRES_PASSWORD: postgres
|
118
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
119
|
+
# Set health checks to wait until postgres has started
|
120
|
+
options: >-
|
121
|
+
--health-cmd pg_isready
|
122
|
+
--health-interval 10s
|
123
|
+
--health-timeout 5s
|
124
|
+
--health-retries 5
|
125
|
+
|
126
|
+
steps:
|
127
|
+
- uses: actions/checkout@v2
|
128
|
+
- name: Set up Ruby
|
129
|
+
uses: ruby/setup-ruby@v1
|
130
|
+
with:
|
131
|
+
ruby-version: ${{ matrix.ruby }}
|
132
|
+
- name: Setup databases
|
133
|
+
run: |
|
134
|
+
psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
|
135
|
+
- name: Install dependencies
|
136
|
+
run: bundle install
|
137
|
+
- name: Run tests
|
138
|
+
run: bundle exec rspec
|
139
|
+
|
140
|
+
bug-report-templates:
|
141
|
+
runs-on: ubuntu-20.04
|
142
|
+
steps:
|
143
|
+
- uses: actions/checkout@v2
|
144
|
+
- name: Set up Ruby
|
145
|
+
uses: ruby/setup-ruby@v1
|
146
|
+
with:
|
147
|
+
ruby-version: 3.0.0
|
148
|
+
- name: Install dependencies
|
149
|
+
run: bundle install
|
150
|
+
- name: Run bug report templates
|
151
|
+
run: |
|
152
|
+
ruby bug_report_templates/test-ransacker-arel-present-predicate.rb
|
153
|
+
ruby bug_report_templates/test-ransack-scope-and-column-same-name.rb
|
154
|
+
rm Gemfile Gemfile.lock
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
|
4
|
+
DisabledByDefault: true
|
5
|
+
|
6
|
+
Layout/EmptyLineAfterMagicComment:
|
7
|
+
Enabled: true
|
8
|
+
|
9
|
+
Layout/EmptyLineBetweenDefs:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Layout/EmptyLines:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
Layout/FirstArrayElementIndentation:
|
16
|
+
EnforcedStyle: consistent
|
17
|
+
|
18
|
+
Layout/SpaceAfterComma:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
Layout/SpaceInsideBlockBraces:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
Layout/SpaceInsideHashLiteralBraces:
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
Layout/SpaceInsideParens:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Layout/TrailingEmptyLines:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Style/RedundantFileExtensionInRequire:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Style/RedundantReturn:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Style/SelfAssignment:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Style/Semicolon:
|
43
|
+
Enabled: true
|
44
|
+
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
|
3
|
+
* Drop support for rubies under 2.5. PR #1189
|
4
|
+
|
5
|
+
## 2.4.1 - 2020-12-21
|
6
|
+
|
7
|
+
* Add `ActiveRecord::Base.ransack!` which raises error if passed unknown condition
|
4
8
|
|
5
|
-
*
|
6
|
-
|
9
|
+
*Aaron Lipman*
|
10
|
+
|
11
|
+
## 2.4.0 - 2020-11-27
|
7
12
|
|
8
13
|
* Support ActiveRecord 6.1.0.rc1.
|
9
14
|
PR [1172](https://github.com/activerecord-hackery/ransack/pull/1172)
|
data/CONTRIBUTING.md
CHANGED
@@ -26,8 +26,8 @@ Steps:
|
|
26
26
|
Ransack and not in your code or another gem.
|
27
27
|
|
28
28
|
4. **Report the issue** by providing the link to a self-contained
|
29
|
-
gist like [this](https://
|
30
|
-
[this](https://
|
29
|
+
gist like [this](https://github.com/activerecord-hackery/ransack/blob/run_bug_report_templates/bug_report_templates/test-ransack-scope-and-column-same-name.rb) or
|
30
|
+
[this](https://github.com/activerecord-hackery/ransack/blob/run_bug_report_templates/bug_report_templates/test-ransacker-arel-present-predicate.rb). Please use
|
31
31
|
these code examples as a bug-report template for your Ransack issue!
|
32
32
|
|
33
33
|
If you do not provide a self-contained gist and would like your issue to be reviewed, do provide at a minimum:
|
@@ -115,9 +115,6 @@ Here's a quick guide:
|
|
115
115
|
$ git config --global user.email "contributor@example.com"
|
116
116
|
|
117
117
|
10. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
|
118
|
-
If your pull request only contains documentation changes, please remember
|
119
|
-
to add `[skip ci]` to the beginning of your commit message so the Travis
|
120
|
-
test suite doesn't :runner: needlessly.
|
121
118
|
|
122
119
|
11. If necessary, rebase your commits into logical chunks, without errors. To
|
123
120
|
interactively rebase and cherry-pick from, say, the last 10 commits:
|
data/Gemfile
CHANGED
@@ -14,8 +14,8 @@ rails_version = case rails
|
|
14
14
|
rails
|
15
15
|
end
|
16
16
|
|
17
|
-
gem 'faker', '~>
|
18
|
-
gem 'sqlite3', ::Gem::Version.new(rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
|
17
|
+
gem 'faker', '~> 2.0'
|
18
|
+
gem 'sqlite3', ::Gem::Version.new(rails_version == 'main' ? '6.2.0.alpha' : rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
|
19
19
|
gem 'pg', '~> 1.0'
|
20
20
|
gem 'pry', '~> 0.12.2'
|
21
21
|
gem 'byebug'
|
@@ -49,3 +49,5 @@ group :test do
|
|
49
49
|
gem 'rspec', '~> 3'
|
50
50
|
gem 'simplecov', :require => false
|
51
51
|
end
|
52
|
+
|
53
|
+
gem 'rubocop', require: false
|
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# ![Ransack](./logo/ransack-h.png "Ransack")
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Please see the [Maintainer wanted issue](https://github.com/activerecord-hackery/ransack/issues/1159) if you are interested.
|
6
|
-
|
7
|
-
[![Build Status](https://travis-ci.org/activerecord-hackery/ransack.svg)](https://travis-ci.org/activerecord-hackery/ransack)
|
3
|
+
[![Build Status](https://github.com/activerecord-hackery/ransack/workflows/test/badge.svg)](https://github.com/activerecord-hackery/ransack/actions)
|
8
4
|
[![Gem Version](https://badge.fury.io/rb/ransack.svg)](http://badge.fury.io/rb/ransack)
|
9
5
|
[![Code Climate](https://codeclimate.com/github/activerecord-hackery/ransack/badges/gpa.svg)](https://codeclimate.com/github/activerecord-hackery/ransack)
|
10
6
|
[![Backers on Open Collective](https://opencollective.com/ransack/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/ransack/sponsors/badge.svg)](#sponsors)
|
@@ -21,7 +17,7 @@ instead.
|
|
21
17
|
|
22
18
|
## Getting started
|
23
19
|
|
24
|
-
Ransack is
|
20
|
+
Ransack is supported for Rails 6.1, 6.0, 5.2 on Ruby 2.6.6 and later.
|
25
21
|
|
26
22
|
In your Gemfile, for the last officially released gem:
|
27
23
|
|
@@ -45,27 +41,14 @@ gem 'ransack', github: 'activerecord-hackery/ransack'
|
|
45
41
|
|
46
42
|
## Usage
|
47
43
|
|
48
|
-
Ransack can be used in one of two modes, simple or advanced.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
This mode works much like MetaSearch, for those of you who are familiar with
|
53
|
-
it, and requires very little setup effort.
|
54
|
-
|
55
|
-
If you're coming from MetaSearch, things to note:
|
56
|
-
|
57
|
-
1. The default param key for search params is now `:q`, instead of `:search`.
|
58
|
-
This is primarily to shorten query strings, though advanced queries (below)
|
59
|
-
will still run afoul of URL length limits in most browsers and require a
|
60
|
-
switch to HTTP POST requests. This key is [configurable](https://github.com/activerecord-hackery/ransack/wiki/Configuration).
|
44
|
+
Ransack can be used in one of two modes, simple or advanced. For
|
45
|
+
searching/filtering not requiring complex boolean logic, Ransack's simple
|
46
|
+
mode should meet your needs.
|
61
47
|
|
62
|
-
|
63
|
-
|
48
|
+
If you're coming from MetaSearch (Ransack's predecessor), refer to the
|
49
|
+
[Updating From MetaSearch](#updating-from-metasearch) section
|
64
50
|
|
65
|
-
|
66
|
-
search object. Instead, you will get your search results (an
|
67
|
-
ActiveRecord::Relation in the case of the ActiveRecord adapter) via a call to
|
68
|
-
`Ransack#result`.
|
51
|
+
### Simple Mode
|
69
52
|
|
70
53
|
#### In your controller
|
71
54
|
|
@@ -88,6 +71,20 @@ def index
|
|
88
71
|
end
|
89
72
|
```
|
90
73
|
|
74
|
+
##### Default search parameter
|
75
|
+
|
76
|
+
Ransack uses a default `:q` param key for search params. This may be changed by
|
77
|
+
setting the `search_key` option in a Ransack initializer file (typically
|
78
|
+
`config/initializers/ransack.rb`):
|
79
|
+
|
80
|
+
```
|
81
|
+
Ransack.configure do |c|
|
82
|
+
# Change default search parameter key name.
|
83
|
+
# Default key name is :q
|
84
|
+
c.search_key = :query
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
91
88
|
#### In your view
|
92
89
|
|
93
90
|
The two primary Ransack view helpers are `search_form_for` and `sort_link`,
|
@@ -254,6 +251,20 @@ the order indicator arrow by passing `hide_indicator: true` in the sort link:
|
|
254
251
|
default_order: { last_name: 'asc', first_name: 'desc' }) %>
|
255
252
|
```
|
256
253
|
|
254
|
+
#### PostgreSQL's sort option
|
255
|
+
|
256
|
+
The `NULLS FIRST` and `NULLS LAST` options can be used to determine whether nulls appear before or after non-null values in the sort ordering.
|
257
|
+
|
258
|
+
You may want to configure it like this:
|
259
|
+
|
260
|
+
```rb
|
261
|
+
Ransack.configure do |c|
|
262
|
+
c.postgres_fields_sort_option = :nulls_first # or :nulls_last
|
263
|
+
end
|
264
|
+
```
|
265
|
+
|
266
|
+
See this feature: https://www.postgresql.org/docs/13/queries-order.html
|
267
|
+
|
257
268
|
### Advanced Mode
|
258
269
|
|
259
270
|
"Advanced" searches (ab)use Rails' nested attributes functionality in order to
|
@@ -674,6 +685,43 @@ Trying it out in `rails console`:
|
|
674
685
|
|
675
686
|
That's it! Now you know how to whitelist/blacklist various elements in Ransack.
|
676
687
|
|
688
|
+
### Handling unknown predicates or attributes
|
689
|
+
|
690
|
+
By default, Ransack will ignore any unknown predicates or attributes:
|
691
|
+
|
692
|
+
```ruby
|
693
|
+
Article.ransack(unknown_attr_eq: 'Ernie').result.to_sql
|
694
|
+
=> SELECT "articles".* FROM "articles"
|
695
|
+
```
|
696
|
+
|
697
|
+
Ransack may be configured to raise an error if passed an unknown predicate or
|
698
|
+
attributes, by setting the `ignore_unknown_conditions` option to `false` in your
|
699
|
+
Ransack initializer file at `config/initializers/ransack.rb`:
|
700
|
+
|
701
|
+
```ruby
|
702
|
+
Ransack.configure do |c|
|
703
|
+
# Raise errors if a query contains an unknown predicate or attribute.
|
704
|
+
# Default is true (do not raise error on unknown conditions).
|
705
|
+
c.ignore_unknown_conditions = false
|
706
|
+
end
|
707
|
+
```
|
708
|
+
|
709
|
+
```ruby
|
710
|
+
Article.ransack(unknown_attr_eq: 'Ernie')
|
711
|
+
# ArgumentError (Invalid search term unknown_attr_eq)
|
712
|
+
```
|
713
|
+
|
714
|
+
As an alternative to setting a global configuration option, the `.ransack!`
|
715
|
+
class method also raises an error if passed an unknown condition:
|
716
|
+
|
717
|
+
```ruby
|
718
|
+
Article.ransack!(unknown_attr_eq: 'Ernie')
|
719
|
+
# ArgumentError: Invalid search term unknown_attr_eq
|
720
|
+
```
|
721
|
+
|
722
|
+
This is equivilent to the `ignore_unknown_conditions` configuration option,
|
723
|
+
except it may be applied on a case-by-case basis.
|
724
|
+
|
677
725
|
### Using Scopes/Class Methods
|
678
726
|
|
679
727
|
Continuing on from the preceding section, searching by scopes requires defining
|
@@ -870,6 +918,28 @@ en:
|
|
870
918
|
title: Old Ransack Namespaced Title
|
871
919
|
```
|
872
920
|
|
921
|
+
### Updating From MetaSearch
|
922
|
+
|
923
|
+
Ransack works much like MetaSearch, for those of you who are familiar with
|
924
|
+
it, and requires very little setup effort.
|
925
|
+
|
926
|
+
If you're coming from MetaSearch, things to note:
|
927
|
+
|
928
|
+
1. The default param key for search params is now `:q`, instead of `:search`.
|
929
|
+
This is primarily to shorten query strings, though advanced queries (below)
|
930
|
+
will still run afoul of URL length limits in most browsers and require a
|
931
|
+
switch to HTTP POST requests. This key is
|
932
|
+
[configurable](default-search-parameter) via setting the `search_key` option
|
933
|
+
in your Ransack intitializer file.
|
934
|
+
|
935
|
+
2. `form_for` is now `search_form_for`, and validates that a Ransack::Search
|
936
|
+
object is passed to it.
|
937
|
+
|
938
|
+
3. Common ActiveRecord::Relation methods are no longer delegated by the
|
939
|
+
search object. Instead, you will get your search results (an
|
940
|
+
ActiveRecord::Relation in the case of the ActiveRecord adapter) via a call to
|
941
|
+
`Ransack#result`.
|
942
|
+
|
873
943
|
## Mongoid
|
874
944
|
|
875
945
|
Mongoid support has been moved to its own gem at [ransack-mongoid](https://github.com/activerecord-hackery/ransack-mongoid).
|