ransack 2.1.1 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/test.yml +120 -0
  5. data/.gitignore +1 -0
  6. data/CHANGELOG.md +54 -1
  7. data/CONTRIBUTING.md +11 -9
  8. data/Gemfile +21 -17
  9. data/README.md +119 -52
  10. data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_association.rb +2 -9
  11. data/lib/polyamorous/{activerecord_5.2.1_ruby_2 → activerecord_5.2_ruby_2}/join_dependency.rb +25 -3
  12. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  13. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
  15. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  16. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  18. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
  19. data/lib/{polyamorous.rb → polyamorous/polyamorous.rb} +3 -4
  20. data/lib/ransack.rb +2 -2
  21. data/lib/ransack/adapters/active_record/base.rb +4 -0
  22. data/lib/ransack/adapters/active_record/context.rb +67 -68
  23. data/lib/ransack/adapters/active_record/ransack/constants.rb +17 -2
  24. data/lib/ransack/adapters/active_record/ransack/context.rb +2 -6
  25. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +12 -5
  26. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -1
  27. data/lib/ransack/configuration.rb +17 -1
  28. data/lib/ransack/constants.rb +2 -3
  29. data/lib/ransack/context.rb +19 -18
  30. data/lib/ransack/helpers/form_builder.rb +5 -11
  31. data/lib/ransack/helpers/form_helper.rb +1 -1
  32. data/lib/ransack/locale/az.yml +1 -1
  33. data/lib/ransack/locale/ca.yml +70 -0
  34. data/lib/ransack/locale/es.yml +22 -22
  35. data/lib/ransack/locale/fa.yml +70 -0
  36. data/lib/ransack/locale/fi.yml +71 -0
  37. data/lib/ransack/locale/sk.yml +70 -0
  38. data/lib/ransack/nodes/condition.rb +8 -0
  39. data/lib/ransack/nodes/grouping.rb +1 -1
  40. data/lib/ransack/predicate.rb +2 -1
  41. data/lib/ransack/search.rb +3 -1
  42. data/lib/ransack/translate.rb +115 -115
  43. data/lib/ransack/version.rb +1 -1
  44. data/ransack.gemspec +5 -21
  45. data/spec/helpers/polyamorous_helper.rb +3 -8
  46. data/spec/{ransack → polyamorous}/join_association_spec.rb +7 -0
  47. data/spec/{ransack → polyamorous}/join_dependency_spec.rb +18 -7
  48. data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
  49. data/spec/ransack/adapters/active_record/base_spec.rb +7 -3
  50. data/spec/ransack/adapters/active_record/context_spec.rb +60 -17
  51. data/spec/ransack/configuration_spec.rb +10 -0
  52. data/spec/ransack/predicate_spec.rb +54 -2
  53. data/spec/ransack/search_spec.rb +127 -15
  54. data/spec/spec_helper.rb +4 -0
  55. data/spec/support/schema.rb +14 -1
  56. metadata +31 -137
  57. data/.travis.yml +0 -37
  58. data/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
  59. data/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
  60. data/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -32
  61. data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
  62. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -32
  63. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -113
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2eab955e89328399bcb163a575725ea51969653edb1edd66773b6f60554fd12
4
- data.tar.gz: 1e6d34f5d87238a18c7ae2194cd0d5320d9460b97b8d8c30ec79d82de6aa139a
3
+ metadata.gz: 2c8153add4e8f7cc4123bb1c6b7f8b6f4db1fdbb65c2d8498a61ef7fc98eea53
4
+ data.tar.gz: 1bae6d37282b621109534060b7c32ecbff7c02366cff88d271d48607ca6fd4cb
5
5
  SHA512:
6
- metadata.gz: 52c4a46725d9bb474fbb229c39d9638c730d77bd53211f00f639b78690fcd72aaaa2418b56704c30024c36c39ca7cebde0e86b76cba13704a26f4416791ad141
7
- data.tar.gz: bd6880992a977511ea37df47d0828e8ee1e855dff39e2620eaed89bc043ffde2960e3006ebcc0609c9738af10faea6947a1db1f91f1f3eebc65b631d97137054
6
+ metadata.gz: ec86fcdc8b81a73c77f3da4e3e9eb2ce7480cae4ce948d64c55d5514d836474fe0c60c727be5d1bca39814afdc96c8bd997e2d245d557689badea217fce67f92
7
+ data.tar.gz: 6526a66311015b73c4132d7c1b95b2006526cf929c47cb5aec91fc79287f07eb0df85a47d22e47d2b88547796501ce8ecb57c81c044e0113f716e45e516b151d
@@ -0,0 +1,3 @@
1
+ ---
2
+
3
+ tidelift: rubygems/ransack
@@ -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,120 @@
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.0.rc2
15
+ - v6.0.3
16
+ - 6-0-stable
17
+ - 5-2-stable
18
+ - v5.2.4
19
+ ruby:
20
+ - 2.7.2
21
+ - 2.6.6
22
+ env:
23
+ DB: sqlite3
24
+ RAILS: ${{ matrix.rails }}
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ - name: Install dependencies
32
+ run: bundle install
33
+ - name: Run tests
34
+ run: bundle exec rspec
35
+
36
+ mysql:
37
+ runs-on: ubuntu-20.04
38
+ strategy:
39
+ fail-fast: false
40
+ matrix:
41
+ rails:
42
+ - v6.1.0.rc2
43
+ - v6.0.3
44
+ - 6-0-stable
45
+ - 5-2-stable
46
+ - v5.2.4
47
+ ruby:
48
+ - 2.7.2
49
+ - 2.6.6
50
+ env:
51
+ DB: mysql
52
+ RAILS: ${{ matrix.rails }}
53
+ MYSQL_USERNAME: root
54
+ MYSQL_PASSWORD: root
55
+ steps:
56
+ - uses: actions/checkout@v2
57
+ - name: Set up Ruby
58
+ uses: ruby/setup-ruby@v1
59
+ with:
60
+ ruby-version: ${{ matrix.ruby }}
61
+ - name: Startup MySQL
62
+ run: |
63
+ sudo systemctl start mysql.service
64
+ - name: Setup databases
65
+ run: |
66
+ mysql --user=root --password=root --host=127.0.0.1 -e 'create database ransack collate utf8_general_ci;';
67
+ mysql --user=root --password=root --host=127.0.0.1 -e 'use ransack;show variables like "%character%";show variables like "%collation%";';
68
+ - name: Install dependencies
69
+ run: bundle install
70
+ - name: Run tests
71
+ run: bundle exec rspec
72
+
73
+ postgres:
74
+ runs-on: ubuntu-20.04
75
+ strategy:
76
+ fail-fast: false
77
+ matrix:
78
+ rails:
79
+ - v6.1.0.rc2
80
+ - v6.0.3
81
+ - 6-0-stable
82
+ - 5-2-stable
83
+ - v5.2.4
84
+ ruby:
85
+ - 2.7.2
86
+ - 2.6.6
87
+ env:
88
+ DB: postgres
89
+ RAILS: ${{ matrix.rails }}
90
+ DATABASE_USERNAME: postgres
91
+ DATABASE_PASSWORD: postgres
92
+ DATABASE_HOST: 127.0.0.1
93
+ services:
94
+ postgres:
95
+ image: postgres
96
+ ports:
97
+ - 5432:5432
98
+ env:
99
+ POSTGRES_PASSWORD: postgres
100
+ POSTGRES_HOST_AUTH_METHOD: trust
101
+ # Set health checks to wait until postgres has started
102
+ options: >-
103
+ --health-cmd pg_isready
104
+ --health-interval 10s
105
+ --health-timeout 5s
106
+ --health-retries 5
107
+
108
+ steps:
109
+ - uses: actions/checkout@v2
110
+ - name: Set up Ruby
111
+ uses: ruby/setup-ruby@v1
112
+ with:
113
+ ruby-version: ${{ matrix.ruby }}
114
+ - name: Setup databases
115
+ run: |
116
+ psql -h localhost -p 5432 -W postgres -c 'create database ransack;' -U postgres;
117
+ - name: Install dependencies
118
+ run: bundle install
119
+ - name: Run tests
120
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  coverage/*
6
6
  .DS_Store
7
+ .byebug_history
@@ -1,6 +1,59 @@
1
1
  # Change Log
2
2
 
3
- ## Unreleased
3
+ * Add `ActiveRecord::Base.ransack!` which raises error if passed unknown condition
4
+
5
+ *Aaron Lipman*
6
+
7
+ ## 2.4.0 - 2020-11-27
8
+
9
+ *
10
+ PR []()
11
+
12
+ * Support ActiveRecord 6.1.0.rc1.
13
+ PR [1172](https://github.com/activerecord-hackery/ransack/pull/1172)
14
+
15
+ * Fix for ActiveRecord 5.2.4 (note security fix in 5.2.4.2 for ActiveView's escape_javascript CVE-2020-5267 for all earlier versions)
16
+
17
+ * Drop support for ActiveRecord older than 5.2.4.
18
+ PR [1166](https://github.com/activerecord-hackery/ransack/pull/1166)
19
+
20
+ ## 2.3.2 - 2020-01-11
21
+
22
+ * Breakfix to bump Polyamorous
23
+
24
+ ## 2.3.1 - 2020-01-11
25
+
26
+ * Drop support for Active Record 5.0, 5.1, and 5.2.0.
27
+ PR [#1073](https://github.com/activerecord-hackery/ransack/pull/1073)
28
+
29
+ * Drop support for rubies under 2.3.
30
+ PR [#1070](https://github.com/activerecord-hackery/ransack/pull/1070)
31
+
32
+ ... and others
33
+
34
+ ## 2.3.0 - 2019-08-18
35
+
36
+ * Arabic translations PR [979](https://github.com/activerecord-hackery/ransack/pull/979)
37
+
38
+ * Rails 6 PR [1027](https://github.com/activerecord-hackery/ransack/pull/1027)
39
+ *vrodokanakis*
40
+
41
+ * Make polyamorous a separate gem PR [1002](https://github.com/activerecord-hackery/ransack/pull/1002)
42
+
43
+ * Catalan translations PR[1007](https://github.com/activerecord-hackery/ransack/pull/1007)
44
+ *roslavych*
45
+
46
+ * Don't escape period characters with wildcard searches in mysql2 PR [1013](https://github.com/activerecord-hackery/ransack/pull/1013)
47
+ *daflip*
48
+
49
+ * Farsi translations PR [1030](https://github.com/activerecord-hackery/ransack/pull/1030)
50
+
51
+ * Finnish translations PR [1049](https://github.com/activerecord-hackery/ransack/pull/1049)
52
+
53
+ * Fix wrong table alias when using nested join. for ActiveRecord >= 5.2
54
+ PR [374](https://github.com/activerecord-hackery/ransack/pull/374)
55
+
56
+ *hiichan*
4
57
 
5
58
  ## Version 2.1.1 - 2018-12-05
6
59
 
@@ -64,6 +64,9 @@ Here's a quick guide:
64
64
  2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
65
65
 
66
66
  3. Install the development dependencies by running `bundle install`.
67
+ To install rails other than latest (set in Gemfile): `RAILS='5-2-stable' bundle install`
68
+
69
+ $ RAILS='5-2-stable' bundle install
67
70
 
68
71
  4. Begin by running the tests. We only take pull requests with passing tests,
69
72
  and it's great to know that you have a clean slate:
@@ -84,16 +87,18 @@ Here's a quick guide:
84
87
  $ mysql -u root
85
88
  mysql> create database ransack;
86
89
 
87
- To run only the tests in a particular file: `rspec <path/to/filename>`
90
+ The test suite runs by default
91
+
92
+ To run only the tests in a particular file: `bundle exec rspec <path/to/filename>`
88
93
 
89
- $ rspec spec/ransack/search_spec.rb
94
+ $ bundle exec rspec spec/ransack/search_spec.rb
90
95
 
91
- To run a single test in that file: `rspec <path/to/filename> -e "test name"`
96
+ To run a single test in that file: `bundle exec rspec <path/to/filename> -e "test name"`
92
97
 
93
- $ rspec spec/ransack/search_spec.rb -e "accepts a context option"
98
+ $ bundle exec rspec spec/ransack/search_spec.rb -e "accepts a context option"
94
99
 
95
- 5. Hack away! Please use Ruby features that are compatible down to Ruby 1.9.
96
- Since version 1.5, Ransack no longer maintains Ruby 1.8 compatibility.
100
+ 5. Hack away! Please use Ruby features that are compatible down to Ruby 2.3.
101
+ Since version 2.3.1, Ransack no longer maintains Ruby 2.2 compatibility.
97
102
 
98
103
  6. Add tests for your changes. Only refactoring and documentation changes
99
104
  require no new tests. If you are adding functionality or fixing a bug, we
@@ -110,9 +115,6 @@ Here's a quick guide:
110
115
  $ git config --global user.email "contributor@example.com"
111
116
 
112
117
  10. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
113
- If your pull request only contains documentation changes, please remember
114
- to add `[skip ci]` to the beginning of your commit message so the Travis
115
- test suite doesn't :runner: needlessly.
116
118
 
117
119
  11. If necessary, rebase your commits into logical chunks, without errors. To
118
120
  interactively rebase and cherry-pick from, say, the last 10 commits:
data/Gemfile CHANGED
@@ -3,45 +3,49 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
 
6
- rails = ENV['RAILS'] || '5-0-stable'
6
+ rails = ENV['RAILS'] || '6-0-stable'
7
7
 
8
- gem 'pry'
8
+ rails_version = case rails
9
+ when /\// # A path
10
+ File.read(File.join(rails, "RAILS_VERSION"))
11
+ when /^v/ # A tagged version
12
+ rails.gsub(/^v/, '')
13
+ else
14
+ rails
15
+ end
9
16
 
10
- # Provide timezone information on Windows
11
- gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
17
+ gem 'faker', '~> 1.0'
18
+ gem 'sqlite3', ::Gem::Version.new(rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
19
+ gem 'pg', '~> 1.0'
20
+ gem 'pry', '~> 0.12.2'
21
+ gem 'byebug'
12
22
 
13
23
  case rails
14
24
  when /\// # A path
15
25
  gem 'activesupport', path: "#{rails}/activesupport"
26
+ gem 'activemodel', path: "#{rails}/activemodel"
16
27
  gem 'activerecord', path: "#{rails}/activerecord", require: false
17
28
  gem 'actionpack', path: "#{rails}/actionpack"
29
+ gem 'actionview', path: "#{rails}/actionview"
18
30
  when /^v/ # A tagged version
19
- git 'git://github.com/rails/rails.git', :tag => rails do
31
+ git 'https://github.com/rails/rails.git', :tag => rails do
20
32
  gem 'activesupport'
21
33
  gem 'activemodel'
22
34
  gem 'activerecord', require: false
23
35
  gem 'actionpack'
24
36
  end
25
- if rails >= 'v5.2.0'
26
- gem 'mysql2', '~> 0.4.4'
27
- end
28
37
  else
29
- git 'git://github.com/rails/rails.git', :branch => rails do
38
+ git 'https://github.com/rails/rails.git', :branch => rails do
30
39
  gem 'activesupport'
31
40
  gem 'activemodel'
32
41
  gem 'activerecord', require: false
33
42
  gem 'actionpack'
34
43
  end
35
- if rails == '3-0-stable'
36
- gem 'mysql2', '< 0.3'
37
- end
38
- if rails == '5-2-stable'
39
- gem 'mysql2', '~> 0.4.4'
40
- end
41
44
  end
45
+ gem 'mysql2', '~> 0.5.2'
42
46
 
43
47
  group :test do
44
- # TestUnit was removed from Ruby 2.2 but still needed for testing Rails 3.x.
45
- gem 'test-unit', '~> 3.0' if RUBY_VERSION >= '2.2'
48
+ gem 'machinist', '~> 1.0.6'
49
+ gem 'rspec', '~> 3'
46
50
  gem 'simplecov', :require => false
47
51
  end
data/README.md CHANGED
@@ -1,19 +1,9 @@
1
1
  # ![Ransack](./logo/ransack-h.png "Ransack")
2
2
 
3
- [![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)
4
4
  [![Gem Version](https://badge.fury.io/rb/ransack.svg)](http://badge.fury.io/rb/ransack)
5
5
  [![Code Climate](https://codeclimate.com/github/activerecord-hackery/ransack/badges/gpa.svg)](https://codeclimate.com/github/activerecord-hackery/ransack)
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)
7
-
8
- Ransack is a rewrite of [MetaSearch](https://github.com/activerecord-hackery/meta_search)
9
- created by [Ernie Miller](http://twitter.com/erniemiller)
10
- and developed/maintained for years by
11
- [Jon Atack](http://twitter.com/jonatack) and
12
- [Ryan Bigg](http://twitter.com/ryanbigg) with the help of a great group of
13
- [contributors](https://github.com/activerecord-hackery/ransack/graphs/contributors). Ransack's logo is designed by [Anıl Kılıç](https://github.com/anilkilic).
14
- While it supports many of the same features as MetaSearch, its underlying
15
- implementation differs greatly from MetaSearch,
16
- and backwards compatibility is not a design goal.
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)
17
7
 
18
8
  Ransack enables the creation of both
19
9
  [simple](http://ransack-demo.herokuapp.com) and
@@ -25,21 +15,9 @@ or controller layer, you're probably not looking for Ransack (or MetaSearch,
25
15
  for that matter). Try [Squeel](https://github.com/activerecord-hackery/squeel)
26
16
  instead.
27
17
 
28
- If you're viewing this at
29
- [github.com/activerecord-hackery/ransack](https://github.com/activerecord-hackery/ransack),
30
- you're reading the documentation for the master branch with the latest features.
31
- [View documentation for the last release (2.0.0).](https://github.com/activerecord-hackery/ransack/tree/v2.0.0)
32
-
33
18
  ## Getting started
34
19
 
35
- Ransack is compatible with Rails 5.0, 5.1 and 5.2 on Ruby 2.2 and later.
36
- If you are using Rails <5.0 use the 1.8 line of Ransack.
37
- If you are using Ruby 1.8 or an earlier JRuby and run into compatibility
38
- issues, you can use an earlier version of Ransack, say, up to 1.3.0.
39
-
40
- Ransack works out-of-the-box with Active Record and also features limited
41
- support for Mongoid 4 and 5 (without associations, further details
42
- [below](https://github.com/activerecord-hackery/ransack#mongoid)).
20
+ Ransack is supported for Rails 6.1, 6.0, 5.2 on Ruby 2.6.6 and later.
43
21
 
44
22
  In your Gemfile, for the last officially released gem:
45
23
 
@@ -63,27 +41,14 @@ gem 'ransack', github: 'activerecord-hackery/ransack'
63
41
 
64
42
  ## Usage
65
43
 
66
- Ransack can be used in one of two modes, simple or advanced.
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.
67
47
 
68
- ### Simple Mode
48
+ If you're coming from MetaSearch (Ransack's predecessor), refer to the
49
+ [Updating From MetaSearch](#updating-from-metasearch) section
69
50
 
70
- This mode works much like MetaSearch, for those of you who are familiar with
71
- it, and requires very little setup effort.
72
-
73
- If you're coming from MetaSearch, things to note:
74
-
75
- 1. The default param key for search params is now `:q`, instead of `:search`.
76
- This is primarily to shorten query strings, though advanced queries (below)
77
- will still run afoul of URL length limits in most browsers and require a
78
- switch to HTTP POST requests. This key is [configurable](https://github.com/activerecord-hackery/ransack/wiki/Configuration).
79
-
80
- 2. `form_for` is now `search_form_for`, and validates that a Ransack::Search
81
- object is passed to it.
82
-
83
- 3. Common ActiveRecord::Relation methods are no longer delegated by the
84
- search object. Instead, you will get your search results (an
85
- ActiveRecord::Relation in the case of the ActiveRecord adapter) via a call to
86
- `Ransack#result`.
51
+ ### Simple Mode
87
52
 
88
53
  #### In your controller
89
54
 
@@ -106,6 +71,20 @@ def index
106
71
  end
107
72
  ```
108
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
+
109
88
  #### In your view
110
89
 
111
90
  The two primary Ransack view helpers are `search_form_for` and `sort_link`,
@@ -272,6 +251,20 @@ the order indicator arrow by passing `hide_indicator: true` in the sort link:
272
251
  default_order: { last_name: 'asc', first_name: 'desc' }) %>
273
252
  ```
274
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
+
275
268
  ### Advanced Mode
276
269
 
277
270
  "Advanced" searches (ab)use Rails' nested attributes functionality in order to
@@ -459,13 +452,10 @@ List of all possible predicates
459
452
  | `*_lteq_any` | Less than or equal to any | |
460
453
  | `*_gt_any` | Greater than any | |
461
454
  | `*_gteq_any` | Greater than or equal to any | |
462
- | `*_matches_any` | `*_does_not_match_any` | same as above but with `LIKE` |
463
455
  | `*_lt_all` | Less than all | SQL: `col < value1 AND col < value2` |
464
456
  | `*_lteq_all` | Less than or equal to all | |
465
457
  | `*_gt_all` | Greater than all | |
466
458
  | `*_gteq_all` | Greater than or equal to all | |
467
- | `*_matches_all` | Matches all | same as above but with `LIKE` |
468
- | `*_does_not_match_all` | Does not match all | |
469
459
  | `*_not_eq_all` | none of values in a set | |
470
460
  | `*_start` | Starts with | SQL: `col LIKE 'value%'` |
471
461
  | `*_not_start` | Does not start with | |
@@ -485,6 +475,12 @@ List of all possible predicates
485
475
  | `*_not_cont` | Does not contain |
486
476
  | `*_not_cont_any` | Does not contain any of | |
487
477
  | `*_not_cont_all` | Does not contain all of | |
478
+ | `*_i_cont` | Contains value with case insensitive | uses `ILIKE` |
479
+ | `*_i_cont_any` | Contains any of values with case insensitive | |
480
+ | `*_i_cont_all` | Contains all of values with case insensitive | |
481
+ | `*_not_i_cont` | Does not contain with case insensitive |
482
+ | `*_not_i_cont_any` | Does not contain any of values with case insensitive | |
483
+ | `*_not_i_cont_all` | Does not contain all of values with case insensitive | |
488
484
  | `*_true` | is true | |
489
485
  | `*_false` | is false | |
490
486
 
@@ -689,6 +685,43 @@ Trying it out in `rails console`:
689
685
 
690
686
  That's it! Now you know how to whitelist/blacklist various elements in Ransack.
691
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
+
692
725
  ### Using Scopes/Class Methods
693
726
 
694
727
  Continuing on from the preceding section, searching by scopes requires defining
@@ -717,8 +750,6 @@ class Employee < ActiveRecord::Base
717
750
  %i(activated hired_since)
718
751
  end
719
752
  end
720
-
721
- private_class_method :ransackable_scopes
722
753
  end
723
754
 
724
755
  Employee.ransack({ activated: true, hired_since: '2013-01-01' })
@@ -753,7 +784,7 @@ To turn this off on a per-scope basis Ransack adds the following method to
753
784
  Add the scope you wish to bypass this behavior to ransackable_scopes_skip_sanitize_args:
754
785
 
755
786
  ```ruby
756
- def ransackable_scopes_skip_sanitize_args
787
+ def self.ransackable_scopes_skip_sanitize_args
757
788
  [:scope_to_skip_sanitize_args]
758
789
  end
759
790
  ```
@@ -887,6 +918,28 @@ en:
887
918
  title: Old Ransack Namespaced Title
888
919
  ```
889
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
+
890
943
  ## Mongoid
891
944
 
892
945
  Mongoid support has been moved to its own gem at [ransack-mongoid](https://github.com/activerecord-hackery/ransack-mongoid).
@@ -924,6 +977,7 @@ In other words: `Major.Minor.Patch`.
924
977
 
925
978
  To support the project:
926
979
 
980
+ * Consider supporting via [Open Collective](https://opencollective.com/ransack/backers/badge.svg)
927
981
  * Use Ransack in your apps, and let us know if you encounter anything that's
928
982
  broken or missing. A failing spec to demonstrate the issue is awesome. A pull
929
983
  request with passing tests is even better!
@@ -939,6 +993,21 @@ fix bugs!
939
993
 
940
994
  This project exists thanks to all the people who contribute. <img src="https://opencollective.com/ransack/contributors.svg?width=890&button=false" />
941
995
 
996
+ Ransack is a rewrite of [MetaSearch](https://github.com/activerecord-hackery/meta_search)
997
+ created by [Ernie Miller](http://twitter.com/erniemiller)
998
+ and developed/maintained by:
999
+
1000
+ - [Greg Molnar](https://github.com/gregmolnar)
1001
+ - [Deivid Rodriguez](https://github.com/deivid-rodriguez)
1002
+ - [Sean Carroll](https://github.com/seanfcarroll)
1003
+ - [Jon Atack](http://twitter.com/jonatack)
1004
+ - [Ryan Bigg](http://twitter.com/ryanbigg)
1005
+ - a great group of [contributors](https://github.com/activerecord-hackery/ransack/graphs/contributors).
1006
+ - Ransack's logo is designed by [Anıl Kılıç](https://github.com/anilkilic).
1007
+
1008
+ While it supports many of the same features as MetaSearch, its underlying implementation differs greatly from MetaSearch, and backwards compatibility is not a design goal.
1009
+
1010
+
942
1011
 
943
1012
  ## Backers
944
1013
 
@@ -961,5 +1030,3 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
961
1030
  <a href="https://opencollective.com/ransack/sponsor/7/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/7/avatar.svg"></a>
962
1031
  <a href="https://opencollective.com/ransack/sponsor/8/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/8/avatar.svg"></a>
963
1032
  <a href="https://opencollective.com/ransack/sponsor/9/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/9/avatar.svg"></a>
964
-
965
-