ransack 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql.yml +72 -0
  3. data/.github/workflows/deploy.yml +35 -0
  4. data/.github/workflows/test-deploy.yml +29 -0
  5. data/.github/workflows/test.yml +22 -39
  6. data/.rubocop.yml +3 -0
  7. data/CHANGELOG.md +118 -0
  8. data/CONTRIBUTING.md +38 -16
  9. data/Gemfile +10 -10
  10. data/README.md +9 -14
  11. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +4 -0
  12. data/docs/.gitignore +0 -1
  13. data/docs/docs/getting-started/advanced-mode.md +1 -1
  14. data/docs/docs/getting-started/search-matches.md +1 -1
  15. data/docs/docs/getting-started/simple-mode.md +30 -26
  16. data/docs/docs/getting-started/sorting.md +1 -1
  17. data/docs/docs/getting-started/using-predicates.md +1 -1
  18. data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
  19. data/docs/docs/going-further/documentation.md +14 -2
  20. data/docs/docs/going-further/exporting-to-csv.md +2 -2
  21. data/docs/docs/going-further/form-customisation.md +1 -1
  22. data/docs/docs/going-further/i18n.md +3 -3
  23. data/docs/docs/going-further/merging-searches.md +1 -1
  24. data/docs/docs/going-further/other-notes.md +1 -1
  25. data/docs/docs/going-further/polymorphic-search.md +40 -0
  26. data/docs/docs/going-further/saving-queries.md +1 -1
  27. data/docs/docs/going-further/searching-postgres.md +1 -1
  28. data/docs/docs/going-further/wiki-contributors.md +82 -0
  29. data/docs/docs/intro.md +2 -2
  30. data/docs/docusaurus.config.js +16 -4
  31. data/docs/package.json +7 -2
  32. data/docs/yarn.lock +3036 -1917
  33. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -1
  34. data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
  35. data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
  36. data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
  37. data/lib/ransack/adapters/active_record/base.rb +78 -7
  38. data/lib/ransack/adapters/active_record/context.rb +17 -49
  39. data/lib/ransack/configuration.rb +25 -12
  40. data/lib/ransack/constants.rb +125 -3
  41. data/lib/ransack/context.rb +34 -5
  42. data/lib/ransack/helpers/form_builder.rb +3 -3
  43. data/lib/ransack/helpers/form_helper.rb +4 -3
  44. data/lib/ransack/nodes/attribute.rb +2 -2
  45. data/lib/ransack/nodes/condition.rb +80 -7
  46. data/lib/ransack/nodes/grouping.rb +3 -3
  47. data/lib/ransack/nodes/node.rb +1 -1
  48. data/lib/ransack/nodes/value.rb +2 -2
  49. data/lib/ransack/predicate.rb +1 -1
  50. data/lib/ransack/ransacker.rb +1 -1
  51. data/lib/ransack/search.rb +9 -4
  52. data/lib/ransack/translate.rb +2 -2
  53. data/lib/ransack/version.rb +1 -1
  54. data/lib/ransack/visitor.rb +38 -2
  55. data/lib/ransack.rb +3 -6
  56. data/ransack.gemspec +3 -3
  57. data/spec/helpers/polyamorous_helper.rb +2 -8
  58. data/spec/ransack/adapters/active_record/base_spec.rb +73 -0
  59. data/spec/ransack/configuration_spec.rb +9 -9
  60. data/spec/ransack/helpers/form_builder_spec.rb +8 -8
  61. data/spec/ransack/helpers/form_helper_spec.rb +60 -2
  62. data/spec/ransack/nodes/condition_spec.rb +24 -0
  63. data/spec/ransack/nodes/value_spec.rb +115 -0
  64. data/spec/ransack/predicate_spec.rb +36 -1
  65. data/spec/ransack/translate_spec.rb +1 -1
  66. data/spec/support/schema.rb +27 -10
  67. metadata +20 -21
  68. data/docs/package-lock.json +0 -9207
  69. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -20
  70. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -79
  71. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -11
  72. data/lib/polyamorous.rb +0 -1
  73. data/lib/ransack/adapters/active_record/ransack/constants.rb +0 -128
  74. data/lib/ransack/adapters/active_record/ransack/context.rb +0 -56
  75. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +0 -69
  76. data/lib/ransack/adapters/active_record/ransack/translate.rb +0 -8
  77. data/lib/ransack/adapters/active_record/ransack/visitor.rb +0 -47
  78. data/lib/ransack/adapters.rb +0 -64
  79. data/lib/ransack/nodes.rb +0 -8
  80. /data/lib/ransack/{adapters/active_record.rb → active_record.rb} +0 -0
data/docs/.gitignore CHANGED
@@ -15,6 +15,5 @@
15
15
  .env.test.local
16
16
  .env.production.local
17
17
 
18
- npm-debug.log*
19
18
  yarn-debug.log*
20
19
  yarn-error.log*
@@ -40,7 +40,7 @@ end
40
40
  html: { method: :post } do |f| %>
41
41
  ```
42
42
 
43
- Once you've done so, you can make use of the helpers in [Ransack::Helpers::FormBuilder](https://github.com/activerecord-hackery/ransack/lib/ransack/helpers/form_builder.rb) to
43
+ Once you've done so, you can make use of the helpers in [Ransack::Helpers::FormBuilder](https://github.com/activerecord-hackery/ransack/blob/main/lib/ransack/helpers/form_builder.rb) to
44
44
  construct much more complex search forms, such as the one on the
45
45
  [demo app](http://ransack-demo.herokuapp.com/users/advanced_search)
46
46
  (source code [here](https://github.com/activerecord-hackery/ransack_demo)).
@@ -64,4 +64,4 @@ List of all possible predicates
64
64
  | `*_false` | is false | |
65
65
 
66
66
 
67
- See full list: https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/locale/en.yml#L15
67
+ See full list: https://github.com/activerecord-hackery/ransack/blob/main/lib/ransack/locale/en.yml#L16
@@ -11,7 +11,7 @@ mode should meet your needs.
11
11
 
12
12
  ## In your controller
13
13
 
14
- ```jsx
14
+ ```ruby
15
15
  def index
16
16
  @q = Person.ransack(params[:q])
17
17
  @people = @q.result(distinct: true)
@@ -20,13 +20,17 @@ end
20
20
  or without `distinct: true`, for sorting on an associated table's columns (in
21
21
  this example, with preloading each Person's Articles and pagination):
22
22
 
23
- ```jsx
23
+ ```ruby
24
24
  def index
25
25
  @q = Person.ransack(params[:q])
26
26
  @people = @q.result.includes(:articles).page(params[:page])
27
27
  end
28
28
  ```
29
29
 
30
+ :::caution
31
+ By default, searching and sorting are authorized on any column of your model. See [Authorization (allowlisting/denylisting)](/going-further/other-notes.md#authorization-allowlistingdenylisting) on how to prevent this.
32
+ :::
33
+
30
34
  ### Default search options
31
35
 
32
36
  #### Search parameter
@@ -35,7 +39,7 @@ Ransack uses a default `:q` param key for search params. This may be changed by
35
39
  setting the `search_key` option in a Ransack initializer file (typically
36
40
  `config/initializers/ransack.rb`):
37
41
 
38
- ```jsx
42
+ ```ruby
39
43
  Ransack.configure do |c|
40
44
  # Change default search parameter key name.
41
45
  # Default key name is :q
@@ -48,9 +52,9 @@ end
48
52
  After version 2.4.0 when searching a string query Ransack by default strips all whitespace around the query string.
49
53
  This may be disabled by setting the `strip_whitespace` option in a Ransack initializer file:
50
54
 
51
- ```jsx
55
+ ```ruby
52
56
  Ransack.configure do |c|
53
- # Change whitespace stripping behaviour.
57
+ # Change whitespace stripping behavior.
54
58
  # Default is true
55
59
  c.strip_whitespace = false
56
60
  end
@@ -60,13 +64,13 @@ end
60
64
 
61
65
  The two primary Ransack view helpers are `search_form_for` and `sort_link`,
62
66
  which are defined in
63
- [Ransack::Helpers::FormHelper](https://github.com/activerecord-hackery/ransack/lib/ransack/helpers/form_helper.rb).
67
+ [Ransack::Helpers::FormHelper](https://github.com/activerecord-hackery/ransack/blob/main/lib/ransack/helpers/form_helper.rb).
64
68
 
65
69
  ### Form helper
66
70
 
67
71
  Ransack's `search_form_for` helper replaces `form_for` for creating the view search form
68
72
 
69
- ```jsx
73
+ ```erb
70
74
  <%= search_form_for @q do |f| %>
71
75
 
72
76
  # Search if the name field contains...
@@ -95,7 +99,7 @@ search predicates.
95
99
 
96
100
  The `search_form_for` answer format can be set like this:
97
101
 
98
- ```jsx
102
+ ```erb
99
103
  <%= search_form_for(@q, format: :pdf) do |f| %>
100
104
 
101
105
  <%= search_form_for(@q, format: :json) do |f| %>
@@ -105,7 +109,7 @@ The `search_form_for` answer format can be set like this:
105
109
 
106
110
  Ransack's `sort_link` helper creates table headers that are sortable links
107
111
 
108
- ```jsx
112
+ ```erb
109
113
  <%= sort_link(@q, :name) %>
110
114
  ```
111
115
  Additional options can be passed after the column parameter, like a different
@@ -114,13 +118,13 @@ column title or a default sort order.
114
118
  If the first option after the column parameter is a String, it's considered a
115
119
  custom label for the link:
116
120
 
117
- ```jsx
121
+ ```erb
118
122
  <%= sort_link(@q, :name, 'Last Name', default_order: :desc) %>
119
123
  ```
120
124
 
121
125
  You can use a block if the link markup is hard to fit into the label parameter:
122
126
 
123
- ```jsx
127
+ ```erb
124
128
  <%= sort_link(@q, :name) do %>
125
129
  <strong>Player Name</strong>
126
130
  <% end %>
@@ -130,14 +134,14 @@ With a polymorphic association, you may need to specify the name of the link
130
134
  explicitly to avoid an `uninitialized constant Model::Xxxable` error (see issue
131
135
  [#421](https://github.com/activerecord-hackery/ransack/issues/421)):
132
136
 
133
- ```jsx
137
+ ```erb
134
138
  <%= sort_link(@q, :xxxable_of_Ymodel_type_some_attribute, 'Attribute Name') %>
135
139
  ```
136
140
 
137
141
  If the first option after the column parameter and/or the label parameter is an
138
142
  Array, it will be used for sorting on multiple fields:
139
143
 
140
- ```jsx
144
+ ```erb
141
145
  <%= sort_link(@q, :last_name, [:last_name, 'first_name asc'], 'Last Name') %>
142
146
  ```
143
147
 
@@ -148,7 +152,7 @@ Ransack to _always_ sort that particular field in the specified direction.
148
152
  Multiple `default_order` fields may also be specified with a trailing options
149
153
  Hash:
150
154
 
151
- ```jsx
155
+ ```erb
152
156
  <%= sort_link(@q, :last_name, %i(last_name first_name),
153
157
  default_order: { last_name: 'asc', first_name: 'desc' }) %>
154
158
  ```
@@ -162,7 +166,7 @@ of a SQL function, you may do so using scopes. In your model, define scopes
162
166
  whose names line up with the name of the virtual field you wish to sort by,
163
167
  as so:
164
168
 
165
- ```jsx
169
+ ```ruby
166
170
  class Person < ActiveRecord::Base
167
171
  scope :sort_by_reverse_name_asc, lambda { order("REVERSE(name) ASC") }
168
172
  scope :sort_by_reverse_name_desc, lambda { order("REVERSE(name) DESC") }
@@ -171,7 +175,7 @@ class Person < ActiveRecord::Base
171
175
 
172
176
  and you can then sort by this virtual field:
173
177
 
174
- ```jsx
178
+ ```erb
175
179
  <%= sort_link(@q, :reverse_name) %>
176
180
  ```
177
181
 
@@ -186,7 +190,7 @@ You can also enable a `default_arrow` which is displayed on all sortable fields
186
190
  which are not currently used in the sorting. This is disabled by default so
187
191
  nothing will be displayed:
188
192
 
189
- ```jsx
193
+ ```ruby
190
194
  Ransack.configure do |c|
191
195
  c.custom_arrows = {
192
196
  up_arrow: '<i class="custom-up-arrow-icon"></i>',
@@ -200,7 +204,7 @@ All sort links may be displayed without the order indicator
200
204
  arrows by setting `hide_sort_order_indicators` to true in the initializer file.
201
205
  Note that this hides the arrows even if they were customized:
202
206
 
203
- ```jsx
207
+ ```ruby
204
208
  Ransack.configure do |c|
205
209
  c.hide_sort_order_indicators = true
206
210
  end
@@ -209,7 +213,7 @@ end
209
213
  Without setting it globally, individual sort links may be displayed without
210
214
  the order indicator arrow by passing `hide_indicator: true` in the sort link:
211
215
 
212
- ```jsx
216
+ ```erb
213
217
  <%= sort_link(@q, :name, hide_indicator: true) %>
214
218
  ```
215
219
 
@@ -219,15 +223,15 @@ Ransack's `sort_url` helper is like a `sort_link` but returns only the url
219
223
 
220
224
  `sort_url` has the same API as `sort_link`:
221
225
 
222
- ```jsx
226
+ ```erb
223
227
  <%= sort_url(@q, :name, default_order: :desc) %>
224
228
  ```
225
229
 
226
- ```jsx
230
+ ```erb
227
231
  <%= sort_url(@q, :last_name, [:last_name, 'first_name asc']) %>
228
232
  ```
229
233
 
230
- ```jsx
234
+ ```erb
231
235
  <%= sort_url(@q, :last_name, %i(last_name first_name),
232
236
  default_order: { last_name: 'asc', first_name: 'desc' }) %>
233
237
  ```
@@ -238,7 +242,7 @@ The `NULLS FIRST` and `NULLS LAST` options can be used to determine whether null
238
242
 
239
243
  You may want to configure it like this:
240
244
 
241
- ```jsx
245
+ ```ruby
242
246
  Ransack.configure do |c|
243
247
  c.postgres_fields_sort_option = :nulls_first # or :nulls_last
244
248
  end
@@ -246,7 +250,7 @@ end
246
250
 
247
251
  To treat nulls as having the lowest or highest value respectively. To force nulls to always be first or last, use
248
252
 
249
- ```jsx
253
+ ```ruby
250
254
  Ransack.configure do |c|
251
255
  c.postgres_fields_sort_option = :nulls_always_first # or :nulls_always_last
252
256
  end
@@ -258,7 +262,7 @@ See this feature: https://www.postgresql.org/docs/13/queries-order.html
258
262
 
259
263
  In order to request PostgreSQL to do a case insensitive sort for all string columns of a model at once, Ransack can be extended by using this approach:
260
264
 
261
- ```jsx
265
+ ```ruby
262
266
  module RansackObject
263
267
 
264
268
  def self.included(base)
@@ -273,7 +277,7 @@ module RansackObject
273
277
  end
274
278
  ```
275
279
 
276
- ```jsx
280
+ ```ruby
277
281
  class UserWithManyAttributes < ActiveRecord::Base
278
282
  include RansackObject
279
283
  end
@@ -9,7 +9,7 @@ title: Sorting
9
9
 
10
10
  You can add a form to capture sorting and filtering options together.
11
11
 
12
- ```jsx
12
+ ```erb
13
13
  <div class="filters" id="filtersSidebar">
14
14
  <header class="filters-header">
15
15
  <div class="filters-header-content">
@@ -23,7 +23,7 @@ You can also combine predicates for OR queries:
23
23
  The syntax for `OR` queries on an associated model is not immediately obvious, but makes sense. Assuming a `User` `has_one` `Account` and the `Account` has `attributes` `foo` and `bar`:
24
24
 
25
25
  ```ruby
26
- >> User.ransack(account_foo_or_account_bar: 'val').result.to_sql
26
+ >> User.ransack(account_foo_or_account_bar_cont: 'val').result.to_sql
27
27
  => SELECT "users".* FROM "users" INNER JOIN accounts ON accounts.user_id = users.id WHERE ("accounts.foo LIKE '%val%' OR accounts.bar LIKE '%val%')
28
28
  ```
29
29
 
@@ -0,0 +1,114 @@
1
+ ---
2
+ title: Acts-as-taggable-on
3
+ sidebar_position: 13
4
+ ---
5
+
6
+ ## Using Acts As Taggable On
7
+
8
+ If you have an `ActiveRecord` model and you're using [acts-as-taggable-on](https://github.com/mbleigh/acts-as-taggable-on),
9
+ chances are you might want to search on tagged fields. Follow the instructions to install the gem and then set up your project files.
10
+
11
+ ### Configure the model
12
+
13
+ `app/models/tasks.rb`
14
+
15
+ You can call the tagging field anything you like, it just needs to be plural. No migration is needed as this is stored in the internal ActsAsTaggable tables (`tags` and `taggings`).
16
+
17
+ ```ruby
18
+ class Task < ApplicationRecord
19
+ acts_as_taggable_on :projects
20
+ end
21
+ ```
22
+
23
+ ### Controller
24
+
25
+ Add a field to strong params in the controller. Use the singular name with `_list`.
26
+
27
+ `app/controllers/tasks_controller.rb`
28
+
29
+ ```ruby
30
+ def strong_params
31
+ params
32
+ .require(:tasks)
33
+ .permit(:task, :example_field, :project_list)
34
+ ```
35
+
36
+ ### Form
37
+
38
+ We need to `send` the tag fieldname to our model, also using the singular naming.
39
+
40
+ ```erb
41
+ <div class='form-group'>
42
+ <%= f.label :project_list %>
43
+ <%= f.text_field :project_list, value: @task.send(:project_list).to_s %>
44
+ </div>
45
+ ```
46
+
47
+ Now we can collect our data via the form, with tags separated by commas.
48
+
49
+ ## Ransack Search
50
+
51
+ Imagine you have the following two instances of `Task`:
52
+
53
+ ```ruby
54
+ { id: 1, name: 'Clean up my room', projects: [ 'Home', 'Personal' ] }
55
+ { id: 2, name: 'Complete math exercises', projects: [ 'Homework', 'Study' ] }
56
+ ```
57
+
58
+ When you're writing a `Ransack` search form, you can choose any of the following options:
59
+
60
+ ```erb
61
+ <%= search_form_for @search do |f| %>
62
+ <%= f.text_field :projects_name_in %> <!-- option a -->
63
+ <%= f.text_field :projects_name_eq %> <!-- option b -->
64
+ <%= f.text_field :projects_name_cont %> <!-- option c -->
65
+ <% end %>
66
+ ```
67
+
68
+ ### Option A - Match keys exactly
69
+
70
+ Option `A` will match keys exactly. This is the solution to choose if you want to distinguish 'Home' from 'Homework': searching for 'Home' will return just the `Task` with id 1. It also allows searching for more than one tag at once (comma separated):
71
+ - `Home, Personal` will return task 1
72
+ - `Home, Homework` will return task 1 and 2
73
+
74
+ ### Option B - match key combinations
75
+
76
+ Option `B` will match all keys exactly. This is the solution if you wanna search for specific combinations of tags:
77
+ - `Home` will return nothing, as there is no Task with just the `Home` tag
78
+ - `Home, Personal` will return task 1
79
+
80
+ ### Option C - match substrings
81
+
82
+ Option `C` is used to match substrings. This is useful when you don't care for the exact tag, but only for part of it:
83
+ - `Home` will return task 1 and 2 (`/Home/` matches both `"Home"` and `"Homework"`)
84
+
85
+ ### Option D - select from a list of tags
86
+
87
+ In Option `D` we allow the user to select a list of valid tags and then search against them. We use the plural name here.
88
+
89
+ ```erb
90
+ <div class='form-group'>
91
+ <%= f.label :projects_name, 'Project' %>
92
+ <%= f.select :projects_name_in, ActsAsTaggableOn::Tag.distinct.order(:name).pluck(:name) %>
93
+ </div>
94
+ ```
95
+
96
+ ## Multitenancy
97
+
98
+ ActsAsTaggableOn allows scoping of tags based on another field on the model. Suppose we have a `language` field on the model, as an effective second level key. We would adjust our model to look like this:
99
+
100
+ ```ruby
101
+ class Task < ApplicationRecord
102
+ acts_as_taggable_on :projects
103
+ acts_as_taggable_tenant :language
104
+ end
105
+ ```
106
+
107
+ The Ransack search is then filtered using the `for_tenant` method
108
+
109
+ ```erb
110
+ <div class='form-group'>
111
+ <%= f.label :projects_name, 'Project' %>
112
+ <%= f.select :projects_name_in, ActsAsTaggableOn::Tag.for_tenant('fr').distinct.order(:name).pluck(:name) %>
113
+ </div>
114
+
@@ -7,12 +7,24 @@ Ransack uses [Docusaurus](https://docusaurus.io/) for documentation. To contribu
7
7
 
8
8
  ### Local Development
9
9
 
10
+ Switch to docs folder
11
+
10
12
  ```
11
13
  cd docs
12
- yarn start
13
14
  ```
14
15
 
15
- This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
16
+ Install docusaurus and other dependencies
17
+
18
+ ```
19
+ yarn install
20
+ ```
21
+
22
+
23
+ Start a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
24
+
25
+ ```
26
+ yarn start
27
+ ```
16
28
 
17
29
  ### Build
18
30
 
@@ -7,7 +7,7 @@ Exporting to CSV
7
7
 
8
8
  Example downloading a csv file preserving ransack search, based on [this gist](https://gist.github.com/pama/adff25ed1f4b796ce088ea362a08e1c5)
9
9
 
10
- ```jsx title='index.html.erb'
10
+ ```ruby title='index.html.erb'
11
11
  <h1>Users</h1>
12
12
 
13
13
  <%= search_form_for @q, url: dashboard_index_path do |f| %>
@@ -30,7 +30,7 @@ Example downloading a csv file preserving ransack search, based on [this gist](h
30
30
  <% end %>
31
31
  ```
32
32
 
33
- ```jsx title='user.rb'
33
+ ```ruby title='user.rb'
34
34
  require 'csv'
35
35
 
36
36
  class User < ApplicationRecord
@@ -3,7 +3,7 @@ sidebar_position: 4
3
3
  title: Form customisation
4
4
  ---
5
5
 
6
- Predicate and attribute labels in forms may be specified with I18n in a translation file (see the locale files in [Ransack::Locale](https://github.com/activerecord-hackery/ransack/activerecord-hackery/ransack/tree/master/lib/ransack/locale) for more examples):
6
+ Predicate and attribute labels in forms may be specified with I18n in a translation file (see the locale files in [Ransack::Locale](https://github.com/activerecord-hackery/ransack/tree/main/lib/ransack/locale) for more examples):
7
7
 
8
8
  ```yml
9
9
  # locales/en.yml
@@ -6,12 +6,12 @@ title: i18n
6
6
  # i18n and Ransack
7
7
 
8
8
  Ransack translation files are available in
9
- [Ransack::Locale](https://github.com/activerecord-hackery/ransack/lib/ransack/locale). You may also be interested in one of the
9
+ [Ransack::Locale](https://github.com/activerecord-hackery/ransack/tree/main/lib/ransack/locale). You may also be interested in one of the
10
10
  many translations for Ransack available at
11
11
  http://www.localeapp.com/projects/2999.
12
12
 
13
13
  Predicate and attribute translations in forms may be specified as follows (see
14
- the translation files in [Ransack::Locale](https://github.com/activerecord-hackery/ransack/lib/ransack/locale) for more examples):
14
+ the translation files in [Ransack::Locale](https://github.com/activerecord-hackery/ransack/tree/main/lib/ransack/locale) for more examples):
15
15
 
16
16
  locales/en.yml:
17
17
  ```yml
@@ -27,7 +27,7 @@ en:
27
27
  gt: greater than
28
28
  lt: less than
29
29
  models:
30
- person: Passanger
30
+ person: Passenger
31
31
  attributes:
32
32
  person:
33
33
  name: Full Name
@@ -38,4 +38,4 @@ WHERE (
38
38
  ORDER BY "people"."id" DESC
39
39
  ```
40
40
 
41
- Admittedly this is not as simple as it should be, but it's workable for now. (Implementing #417 could make this more straightforward.)
41
+ Admittedly this is not as simple as it should be, but it's workable for now. (Implementing [issue 417](https://github.com/activerecord-hackery/ransack/issues/417) could make this more straightforward.)
@@ -354,7 +354,7 @@ argument are not easily usable yet, because the array currently needs to be
354
354
  wrapped in an array to function (see
355
355
  [this issue](https://github.com/activerecord-hackery/ransack/issues/404)),
356
356
  which is not compatible with Ransack form helpers. For this use case, it may be
357
- better for now to use [ransackers](https://github.com/activerecord-hackery/ransack/wiki/Using-Ransackers) instead,
357
+ better for now to use [ransackers](https://activerecord-hackery.github.io/ransack/going-further/ransackers) instead,
358
358
  where feasible. Pull requests with solutions and tests are welcome!
359
359
 
360
360
  ### Grouping queries by OR instead of AND
@@ -0,0 +1,40 @@
1
+ ---
2
+ title: Polymorphic Searches
3
+ sidebar_position: 14
4
+ ---
5
+
6
+ When making searches from polymorphic models it is necessary to specify the type of model you are searching.
7
+
8
+ For example:
9
+
10
+ Given two models
11
+
12
+ ```ruby
13
+ class House < ActiveRecord::Base
14
+ has_one :location, as: :locatable
15
+ end
16
+
17
+ class Location < ActiveRecord::Base
18
+ belongs_to :locatable, polymorphic: true
19
+ end
20
+ ```
21
+
22
+ Normally (without polymorphic relationship) you would be able to search as per below:
23
+
24
+ ```ruby
25
+ Location.ransack(locatable_number_eq: 100).result
26
+ ```
27
+
28
+ However when this is searched you will get the following error
29
+
30
+ ```ruby
31
+ ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :locatable
32
+ ```
33
+
34
+ In order to search for locations by house number when the relationship is polymorphic you have to specify the type of records you will be searching and construct your search as below:
35
+
36
+ ```ruby
37
+ Location.ransack(locatable_of_House_type_number_eq: 100).result
38
+ ```
39
+
40
+ note the `_of_House_type_` added to the search key. This allows Ransack to correctly specify the table names in SQL join queries.
@@ -72,7 +72,7 @@ class ApplicationController < ActionController::Base
72
72
  end
73
73
 
74
74
  protected
75
- # GENERATE A GENERIC SESSION KEY BASED ON TEH CONTROLLER NAME
75
+ # GENERATE A GENERIC SESSION KEY BASED ON THE CONTROLLER NAME
76
76
  def search_key
77
77
  "#{controller_name}_search".to_sym
78
78
  end
@@ -13,7 +13,7 @@ See [this issue](https://github.com/activerecord-hackery/ransack/issues/321) for
13
13
 
14
14
  ### Using a fixed key
15
15
 
16
- See here for searching on a fixed key in a JSONB column: https://github.com/activerecord-hackery/ransack/wiki/Using-Ransackers#3-search-on-a-fixed-key-in-a-jsonb--hstore-column
16
+ See here for searching on a fixed key in a JSONB column: https://activerecord-hackery.github.io/ransack/going-further/ransackers/#postgres-columns
17
17
 
18
18
  ### Using the JSONB contains operator
19
19
 
@@ -0,0 +1,82 @@
1
+ ---
2
+ title: Wiki Contributors
3
+ sidebar_position: 20
4
+ ---
5
+
6
+ Ransack previously had documentation contained in a GitHub Wiki, and this content has been merged into this documentation website. The following long list of _amazing_ people all made contributions to the Wiki:
7
+
8
+ * Abinoam P. Marques Jr
9
+ * Alex Stophel
10
+ * Andrea Schiavini
11
+ * Andrew Vit
12
+ * Ben Koshy
13
+ * Brainkurv
14
+ * Brandan Lennox
15
+ * Brendon Muir
16
+ * Chris Salzberg
17
+ * Colleen McGuckin
18
+ * David Aldridge
19
+ * Davidson Mohanty
20
+ * Denis Tataurov
21
+ * Drew Moore
22
+ * Eike Send
23
+ * Feodor Cherashev
24
+ * Glauco Custódio
25
+ * Grey Baker
26
+ * Harold.Luo
27
+ * Herman Singh
28
+ * Ian Smith
29
+ * Jake Haber
30
+ * Jan Klimo
31
+ * Jared Beck
32
+ * Jon Atack
33
+ * Juanito Fatas
34
+ * JungaJk
35
+ * Leo Chen
36
+ * Leon Miller-Out
37
+ * Luca F
38
+ * Marc Poris
39
+ * Matt Oakley
40
+ * Michael Kopchick
41
+ * Nathan Colgate
42
+ * Nguyen Phi Viet(Sun*)
43
+ * Nguyễn Đức Long
44
+ * NielsKSchjoedt
45
+ * Patrick Copeland
46
+ * Pedro Chambino
47
+ * Rene Hopf
48
+ * Richa Arora
49
+ * Rob Jones
50
+ * Roman Sokhan
51
+ * Ryan Bates
52
+ * Ryan Bigg
53
+ * Sean
54
+ * Sean Linsley
55
+ * Sergey
56
+ * Sunny Ripert
57
+ * Tanbir Hasan
58
+ * ThuyNguyen97
59
+ * Vanda
60
+ * Yana Agun Siswanto
61
+ * bonyiii
62
+ * charly
63
+ * chifung7
64
+ * colorfulberry
65
+ * ddonahue99
66
+ * ernie
67
+ * gaaady
68
+ * gingerlime
69
+ * grumpit
70
+ * itsalongstory
71
+ * jonatack
72
+ * kogre
73
+ * nguyentrungson97
74
+ * nslocum
75
+ * omitter
76
+ * radar
77
+ * rilian
78
+ * terraplane
79
+ * tyronewilson
80
+ * vansy61
81
+ * willnet
82
+ * wzcolon
data/docs/docs/intro.md CHANGED
@@ -17,7 +17,7 @@ Ransack is supported for Rails 7.0, 6.x on Ruby 2.6.6 and later.
17
17
 
18
18
  To install `ransack` and add it to your Gemfile, run
19
19
 
20
- ```jsx title='Gemfile'
20
+ ```ruby title='Gemfile'
21
21
  gem 'ransack'
22
22
  ```
23
23
 
@@ -25,7 +25,7 @@ gem 'ransack'
25
25
 
26
26
  If you would like to use the latest updates not yet published to RubyGems, use the `main` branch:
27
27
 
28
- ```jsx title='Gemfile'
28
+ ```ruby title='Gemfile'
29
29
  gem 'ransack', :github => 'activerecord-hackery/ransack', :branch => 'main'
30
30
  ```
31
31