ransack 2.3.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) 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/codeql.yml +72 -0
  5. data/.github/workflows/cronjob.yml +99 -0
  6. data/.github/workflows/deploy.yml +35 -0
  7. data/.github/workflows/rubocop.yml +20 -0
  8. data/.github/workflows/test-deploy.yml +29 -0
  9. data/.github/workflows/test.yml +131 -0
  10. data/.nojekyll +0 -0
  11. data/.rubocop.yml +50 -0
  12. data/CHANGELOG.md +263 -1
  13. data/CONTRIBUTING.md +51 -29
  14. data/Gemfile +24 -10
  15. data/README.md +49 -917
  16. data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
  17. data/bug_report_templates/test-ransacker-arel-present-predicate.rb +75 -0
  18. data/docs/.gitignore +19 -0
  19. data/docs/.nojekyll +0 -0
  20. data/docs/babel.config.js +3 -0
  21. data/docs/blog/2022-03-27-ransack-3.0.0.md +20 -0
  22. data/docs/docs/getting-started/_category_.json +4 -0
  23. data/docs/docs/getting-started/advanced-mode.md +46 -0
  24. data/docs/docs/getting-started/configuration.md +47 -0
  25. data/docs/docs/getting-started/search-matches.md +67 -0
  26. data/docs/docs/getting-started/simple-mode.md +288 -0
  27. data/docs/docs/getting-started/sorting.md +71 -0
  28. data/docs/docs/getting-started/using-predicates.md +282 -0
  29. data/docs/docs/going-further/_category_.json +4 -0
  30. data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
  31. data/docs/docs/going-further/associations.md +70 -0
  32. data/docs/docs/going-further/custom-predicates.md +52 -0
  33. data/docs/docs/going-further/documentation.md +43 -0
  34. data/docs/docs/going-further/exporting-to-csv.md +49 -0
  35. data/docs/docs/going-further/external-guides.md +57 -0
  36. data/docs/docs/going-further/form-customisation.md +63 -0
  37. data/docs/docs/going-further/i18n.md +53 -0
  38. data/docs/docs/going-further/img/create_release.png +0 -0
  39. data/docs/docs/going-further/merging-searches.md +41 -0
  40. data/docs/docs/going-further/other-notes.md +428 -0
  41. data/docs/docs/going-further/polymorphic-search.md +46 -0
  42. data/docs/docs/going-further/ransackers.md +331 -0
  43. data/docs/docs/going-further/release_process.md +36 -0
  44. data/docs/docs/going-further/saving-queries.md +82 -0
  45. data/docs/docs/going-further/searching-postgres.md +57 -0
  46. data/docs/docs/going-further/wiki-contributors.md +82 -0
  47. data/docs/docs/intro.md +99 -0
  48. data/docs/docusaurus.config.js +120 -0
  49. data/docs/package.json +42 -0
  50. data/docs/sidebars.js +31 -0
  51. data/docs/src/components/HomepageFeatures/index.js +64 -0
  52. data/docs/src/components/HomepageFeatures/styles.module.css +11 -0
  53. data/docs/src/css/custom.css +39 -0
  54. data/docs/src/pages/index.module.css +23 -0
  55. data/docs/src/pages/markdown-page.md +7 -0
  56. data/docs/static/.nojekyll +0 -0
  57. data/docs/static/img/docusaurus.png +0 -0
  58. data/docs/static/img/favicon.ico +0 -0
  59. data/docs/static/img/logo.svg +1 -0
  60. data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
  61. data/docs/static/img/tutorial/localeDropdown.png +0 -0
  62. data/docs/static/img/undraw_docusaurus_mountain.svg +171 -0
  63. data/docs/static/img/undraw_docusaurus_react.svg +170 -0
  64. data/docs/static/img/undraw_docusaurus_tree.svg +40 -0
  65. data/docs/yarn.lock +8879 -0
  66. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +70 -0
  67. data/{polyamorous/lib/polyamorous/activerecord_6.0_ruby_2 → lib/polyamorous/activerecord_6.1_ruby_2}/join_dependency.rb +33 -12
  68. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -0
  69. data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
  70. data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
  71. data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
  72. data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
  73. data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
  74. data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
  75. data/{polyamorous/lib → lib/polyamorous}/polyamorous.rb +3 -8
  76. data/lib/ransack/adapters/active_record/base.rb +83 -10
  77. data/lib/ransack/adapters/active_record/context.rb +61 -116
  78. data/lib/ransack/configuration.rb +53 -10
  79. data/lib/ransack/constants.rb +126 -7
  80. data/lib/ransack/context.rb +34 -5
  81. data/lib/ransack/helpers/form_builder.rb +11 -17
  82. data/lib/ransack/helpers/form_helper.rb +14 -5
  83. data/lib/ransack/helpers.rb +1 -1
  84. data/lib/ransack/locale/sk.yml +70 -0
  85. data/lib/ransack/locale/sv.yml +70 -0
  86. data/lib/ransack/nodes/attribute.rb +3 -3
  87. data/lib/ransack/nodes/condition.rb +87 -8
  88. data/lib/ransack/nodes/grouping.rb +4 -4
  89. data/lib/ransack/nodes/node.rb +1 -1
  90. data/lib/ransack/nodes/sort.rb +3 -3
  91. data/lib/ransack/nodes/value.rb +3 -3
  92. data/lib/ransack/predicate.rb +3 -2
  93. data/lib/ransack/ransacker.rb +1 -1
  94. data/lib/ransack/search.rb +15 -7
  95. data/lib/ransack/translate.rb +6 -6
  96. data/lib/ransack/version.rb +1 -1
  97. data/lib/ransack/visitor.rb +38 -2
  98. data/lib/ransack.rb +6 -10
  99. data/ransack.gemspec +9 -24
  100. data/spec/blueprints/articles.rb +1 -1
  101. data/spec/blueprints/comments.rb +1 -1
  102. data/spec/blueprints/notes.rb +1 -1
  103. data/spec/blueprints/tags.rb +1 -1
  104. data/spec/console.rb +5 -5
  105. data/spec/helpers/polyamorous_helper.rb +2 -17
  106. data/spec/helpers/ransack_helper.rb +1 -1
  107. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  108. data/spec/{ransack → polyamorous}/join_association_spec.rb +3 -1
  109. data/spec/{ransack → polyamorous}/join_dependency_spec.rb +0 -16
  110. data/spec/ransack/adapters/active_record/base_spec.rb +125 -16
  111. data/spec/ransack/adapters/active_record/context_spec.rb +19 -18
  112. data/spec/ransack/configuration_spec.rb +33 -9
  113. data/spec/ransack/helpers/form_builder_spec.rb +8 -8
  114. data/spec/ransack/helpers/form_helper_spec.rb +109 -20
  115. data/spec/ransack/nodes/condition_spec.rb +37 -0
  116. data/spec/ransack/nodes/grouping_spec.rb +2 -2
  117. data/spec/ransack/nodes/value_spec.rb +115 -0
  118. data/spec/ransack/predicate_spec.rb +75 -2
  119. data/spec/ransack/search_spec.rb +239 -38
  120. data/spec/ransack/translate_spec.rb +1 -1
  121. data/spec/spec_helper.rb +9 -5
  122. data/spec/support/schema.rb +111 -12
  123. metadata +105 -195
  124. data/.travis.yml +0 -49
  125. data/lib/ransack/adapters/active_record/ransack/constants.rb +0 -116
  126. data/lib/ransack/adapters/active_record/ransack/context.rb +0 -60
  127. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +0 -61
  128. data/lib/ransack/adapters/active_record/ransack/translate.rb +0 -8
  129. data/lib/ransack/adapters/active_record/ransack/visitor.rb +0 -47
  130. data/lib/ransack/adapters.rb +0 -64
  131. data/lib/ransack/nodes.rb +0 -8
  132. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +0 -2
  133. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +0 -2
  134. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +0 -31
  135. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +0 -112
  136. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +0 -31
  137. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +0 -112
  138. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb +0 -12
  139. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +0 -22
  140. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +0 -81
  141. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +0 -2
  142. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +0 -2
  143. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +0 -2
  144. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -2
  145. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -2
  146. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +0 -2
  147. data/polyamorous/lib/polyamorous/version.rb +0 -3
  148. data/polyamorous/polyamorous.gemspec +0 -35
  149. /data/{logo → docs/static/logo}/ransack-h.png +0 -0
  150. /data/{logo → docs/static/logo}/ransack-h.svg +0 -0
  151. /data/{logo → docs/static/logo}/ransack-v.png +0 -0
  152. /data/{logo → docs/static/logo}/ransack-v.svg +0 -0
  153. /data/{logo → docs/static/logo}/ransack.png +0 -0
  154. /data/{logo → docs/static/logo}/ransack.svg +0 -0
  155. /data/{polyamorous/lib → lib}/polyamorous/join.rb +0 -0
  156. /data/{polyamorous/lib → lib}/polyamorous/swapping_reflection_class.rb +0 -0
  157. /data/{polyamorous/lib → lib}/polyamorous/tree_node.rb +0 -0
  158. /data/lib/ransack/{adapters/active_record.rb → active_record.rb} +0 -0
  159. /data/spec/{ransack → polyamorous}/join_spec.rb +0 -0
data/README.md CHANGED
@@ -1,944 +1,78 @@
1
- # ![Ransack](./logo/ransack-h.png "Ransack")
1
+ # ![Ransack](./docs/static/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.
17
-
18
- Ransack enables the creation of both
19
- [simple](http://ransack-demo.herokuapp.com) and
20
- [advanced](http://ransack-demo.herokuapp.com/users/advanced_search) search forms
21
- for your Ruby on Rails application
22
- ([demo source code here](https://github.com/activerecord-hackery/ransack_demo)).
23
- If you're looking for something that simplifies query generation at the model
24
- or controller layer, you're probably not looking for Ransack (or MetaSearch,
25
- for that matter). Try [Squeel](https://github.com/activerecord-hackery/squeel)
26
- instead.
27
-
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
- ## Rails 6 Support
34
-
35
- Rails 6 is right around the corner, but not yet released. Ransack master branch supports ```6.0.0.rc2```. Full Rails 6 support will be provided after the official Rails 6 release. See [this issue](https://github.com/activerecord-hackery/ransack/issues/1032) for details.
36
-
37
- ## Getting started
38
-
39
- Ransack is compatible with Rails 6.0.0.rc2, 5.0, 5.1 and 5.2 on Ruby 2.2 and later.
40
- If you are using Rails <5.0 use the 1.8 line of Ransack.
41
- If you are using Ruby 1.8 or an earlier JRuby and run into compatibility
42
- issues, you can use an earlier version of Ransack, say, up to 1.3.0.
43
-
44
- Ransack works out-of-the-box with Active Record and also features limited
45
- support for Mongoid 4 and 5 (without associations, further details
46
- [below](https://github.com/activerecord-hackery/ransack#mongoid)).
47
-
48
- In your Gemfile, for the last officially released gem:
49
-
50
- ```ruby
51
- gem 'ransack'
52
- ```
53
-
54
- If you would like to use the latest updates (recommended), use the `master`
55
- branch:
56
-
57
- ```ruby
58
- gem 'ransack', github: 'activerecord-hackery/ransack'
59
- ```
60
-
61
- ## Issues tracker
62
-
63
- * Before filing an issue, please read the [Contributing Guide](CONTRIBUTING.md).
64
- * File an issue if a bug is caused by Ransack, is new (has not already been reported), and _can be reproduced from the information you provide_.
65
- * Contributions are welcome, but please do not add "+1" comments to issues or pull requests :smiley:
66
- * Please do not use the issue tracker for personal support requests. Stack Overflow is a better place for that where a wider community can help you!
67
-
68
- ## Usage
69
-
70
- Ransack can be used in one of two modes, simple or advanced.
71
-
72
- ### Simple Mode
73
-
74
- This mode works much like MetaSearch, for those of you who are familiar with
75
- it, and requires very little setup effort.
76
-
77
- If you're coming from MetaSearch, things to note:
78
-
79
- 1. The default param key for search params is now `:q`, instead of `:search`.
80
- This is primarily to shorten query strings, though advanced queries (below)
81
- will still run afoul of URL length limits in most browsers and require a
82
- switch to HTTP POST requests. This key is [configurable](https://github.com/activerecord-hackery/ransack/wiki/Configuration).
83
-
84
- 2. `form_for` is now `search_form_for`, and validates that a Ransack::Search
85
- object is passed to it.
86
-
87
- 3. Common ActiveRecord::Relation methods are no longer delegated by the
88
- search object. Instead, you will get your search results (an
89
- ActiveRecord::Relation in the case of the ActiveRecord adapter) via a call to
90
- `Ransack#result`.
91
-
92
- #### In your controller
93
-
94
- ```ruby
95
- def index
96
- @q = Person.ransack(params[:q])
97
- @people = @q.result(distinct: true)
98
- end
99
- ```
100
- or without `distinct: true`, for sorting on an associated table's columns (in
101
- this example, with preloading each Person's Articles and pagination):
102
-
103
- ```ruby
104
- def index
105
- @q = Person.ransack(params[:q])
106
- @people = @q.result.includes(:articles).page(params[:page])
107
-
108
- # or use `to_a.uniq` to remove duplicates (can also be done in the view):
109
- @people = @q.result.includes(:articles).page(params[:page]).to_a.uniq
110
- end
111
- ```
112
-
113
- #### In your view
114
-
115
- The two primary Ransack view helpers are `search_form_for` and `sort_link`,
116
- which are defined in
117
- [Ransack::Helpers::FormHelper](lib/ransack/helpers/form_helper.rb).
118
-
119
- #### Ransack's `search_form_for` helper replaces `form_for` for creating the view search form
120
-
121
- ```erb
122
- <%= search_form_for @q do |f| %>
123
-
124
- # Search if the name field contains...
125
- <%= f.label :name_cont %>
126
- <%= f.search_field :name_cont %>
127
-
128
- # Search if an associated articles.title starts with...
129
- <%= f.label :articles_title_start %>
130
- <%= f.search_field :articles_title_start %>
131
-
132
- # Attributes may be chained. Search multiple attributes for one value...
133
- <%= f.label :name_or_description_or_email_or_articles_title_cont %>
134
- <%= f.search_field :name_or_description_or_email_or_articles_title_cont %>
135
-
136
- <%= f.submit %>
137
- <% end %>
138
- ```
139
-
140
- The argument of `f.search_field` has to be in this form:
141
- `attribute_name[_or_attribute_name]..._predicate`
142
-
143
- where `[_or_another_attribute_name]...` means any repetition of `_or_` plus the name of the attribute.
144
-
145
- `cont` (contains) and `start` (starts with) are just two of the available
146
- search predicates. See
147
- [Constants](https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/constants.rb)
148
- for a full list and the
149
- [wiki](https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching)
150
- for more information.
151
-
152
- The `search_form_for` answer format can be set like this:
153
-
154
- ```erb
155
- <%= search_form_for(@q, format: :pdf) do |f| %>
156
-
157
- <%= search_form_for(@q, format: :json) do |f| %>
158
- ```
159
-
160
- #### Ransack's `sort_link` helper creates table headers that are sortable links
161
-
162
- ```erb
163
- <%= sort_link(@q, :name) %>
164
- ```
165
- Additional options can be passed after the column attribute, like a different
166
- column title or a default sort order:
167
-
168
- ```erb
169
- <%= sort_link(@q, :name, 'Last Name', default_order: :desc) %>
170
- ```
171
-
172
- You can use a block if the link markup is hard to fit into the label parameter:
173
-
174
- ```erb
175
- <%= sort_link(@q, :name) do %>
176
- <strong>Player Name</strong>
177
- <% end %>
178
- ```
179
-
180
- With a polymorphic association, you may need to specify the name of the link
181
- explicitly to avoid an `uninitialized constant Model::Xxxable` error (see issue
182
- [#421](https://github.com/activerecord-hackery/ransack/issues/421)):
183
-
184
- ```erb
185
- <%= sort_link(@q, :xxxable_of_Ymodel_type_some_attribute, 'Attribute Name') %>
186
- ```
187
-
188
- You can also sort on multiple fields by specifying an ordered array:
189
-
190
- ```erb
191
- <%= sort_link(@q, :last_name, [:last_name, 'first_name asc'], 'Last Name') %>
192
- ```
193
-
194
- In the example above, clicking the link will sort by `last_name` and then
195
- `first_name`. Specifying the sort direction on a field in the array tells
196
- Ransack to _always_ sort that particular field in the specified direction.
197
-
198
- Multiple `default_order` fields may also be specified with a hash:
199
-
200
- ```erb
201
- <%= sort_link(@q, :last_name, %i(last_name first_name),
202
- default_order: { last_name: 'asc', first_name: 'desc' }) %>
203
- ```
204
-
205
- This example toggles the sort directions of both fields, by default
206
- initially sorting the `last_name` field by ascending order, and the
207
- `first_name` field by descending order.
208
-
209
- In the case that you wish to sort by some complex value, such as the result
210
- of a SQL function, you may do so using scopes. In your model, define scopes
211
- whose names line up with the name of the virtual field you wish to sort by,
212
- as so:
213
-
214
- ```ruby
215
- class Person < ActiveRecord::Base
216
- scope :sort_by_reverse_name_asc, lambda { order("REVERSE(name) ASC") }
217
- scope :sort_by_reverse_name_desc, lambda { order("REVERSE(name) DESC") }
218
- ...
219
- ```
220
-
221
- and you can then sort by this virtual field:
222
-
223
- ```erb
224
- <%= sort_link(@q, :reverse_name) %>
225
- ```
226
-
227
- The sort link order indicator arrows may be globally customized by setting a
228
- `custom_arrows` option in an initializer file like
229
- `config/initializers/ransack.rb`.
230
-
231
- You can also enable a `default_arrow` which is displayed on all sortable fields
232
- which are not currently used in the sorting. This is disabled by default so
233
- nothing will be displayed:
234
-
235
- ```ruby
236
- Ransack.configure do |c|
237
- c.custom_arrows = {
238
- up_arrow: '<i class="custom-up-arrow-icon"></i>',
239
- down_arrow: 'U+02193',
240
- default_arrow: '<i class="default-arrow-icon"></i>'
241
- }
242
- end
243
- ```
244
-
245
- All sort links may be displayed without the order indicator
246
- arrows by setting `hide_sort_order_indicators` to true in the initializer file.
247
- Note that this hides the arrows even if they were customized:
248
-
249
- ```ruby
250
- Ransack.configure do |c|
251
- c.hide_sort_order_indicators = true
252
- end
253
- ```
254
-
255
- Without setting it globally, individual sort links may be displayed without
256
- the order indicator arrow by passing `hide_indicator: true` in the sort link:
257
-
258
- ```erb
259
- <%= sort_link(@q, :name, hide_indicator: true) %>
260
- ```
261
-
262
- #### Ransack's `sort_url` helper is like a `sort_link` but returns only the url
263
-
264
- `sort_url` has the same API as `sort_link`:
265
-
266
- ```erb
267
- <%= sort_url(@q, :name, default_order: :desc) %>
268
- ```
269
-
270
- ```erb
271
- <%= sort_url(@q, :last_name, [:last_name, 'first_name asc']) %>
272
- ```
273
-
274
- ```erb
275
- <%= sort_url(@q, :last_name, %i(last_name first_name),
276
- default_order: { last_name: 'asc', first_name: 'desc' }) %>
277
- ```
278
-
279
- ### Advanced Mode
280
-
281
- "Advanced" searches (ab)use Rails' nested attributes functionality in order to
282
- generate complex queries with nested AND/OR groupings, etc. This takes a bit
283
- more work but can generate some pretty cool search interfaces that put a lot of
284
- power in the hands of your users. A notable drawback with these searches is
285
- that the increased size of the parameter string will typically force you to use
286
- the HTTP POST method instead of GET. :(
287
-
288
- This means you'll need to tweak your routes...
289
-
290
- ```ruby
291
- resources :people do
292
- collection do
293
- match 'search' => 'people#search', via: [:get, :post], as: :search
294
- end
295
- end
296
- ```
297
-
298
- ... and add another controller action ...
299
-
300
- ```ruby
301
- def search
302
- index
303
- render :index
304
- end
305
- ```
306
-
307
- ... and update your `search_form_for` line in the view ...
308
-
309
- ```erb
310
- <%= search_form_for @q, url: search_people_path,
311
- html: { method: :post } do |f| %>
312
- ```
313
-
314
- Once you've done so, you can make use of the helpers in [Ransack::Helpers::FormBuilder](lib/ransack/helpers/form_builder.rb) to
315
- construct much more complex search forms, such as the one on the
316
- [demo app](http://ransack-demo.herokuapp.com/users/advanced_search)
317
- (source code [here](https://github.com/activerecord-hackery/ransack_demo)).
318
-
319
- ### Ransack #search method
320
-
321
- Ransack will try to make the class method `#search` available in your
322
- models, but if `#search` has already been defined elsewhere, you can always use
323
- the default `#ransack` class method. So the following are equivalent:
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)
324
7
 
325
- ```ruby
326
- Article.ransack(params[:q])
327
- Article.search(params[:q])
328
- ```
329
-
330
- Users have reported issues of `#search` name conflicts with other gems, so
331
- the `#search` method alias will be deprecated in the next major version of
332
- Ransack (2.0). It's advisable to use the default `#ransack` instead.
333
-
334
- For now, if Ransack's `#search` method conflicts with the name of another
335
- method named `search` in your code or another gem, you may resolve it either by
336
- patching the `extended` class_method in `Ransack::Adapters::ActiveRecord::Base`
337
- to remove the line `alias :search :ransack unless base.respond_to? :search`, or
338
- by placing the following line in your Ransack initializer file at
339
- `config/initializers/ransack.rb`:
340
-
341
- ```ruby
342
- Ransack::Adapters::ActiveRecord::Base.class_eval('remove_method :search')
343
- ```
344
-
345
- ### Associations
346
-
347
- You can easily use Ransack to search for objects in `has_many` and `belongs_to`
348
- associations.
349
-
350
- Given these associations...
351
-
352
- ```ruby
353
- class Employee < ActiveRecord::Base
354
- belongs_to :supervisor
355
-
356
- # has attributes first_name:string and last_name:string
357
- end
358
-
359
- class Department < ActiveRecord::Base
360
- has_many :supervisors
361
-
362
- # has attribute title:string
363
- end
364
-
365
- class Supervisor < ActiveRecord::Base
366
- belongs_to :department
367
- has_many :employees
368
-
369
- # has attribute last_name:string
370
- end
371
- ```
372
-
373
- ... and a controller...
374
-
375
- ```ruby
376
- class SupervisorsController < ApplicationController
377
- def index
378
- @q = Supervisor.ransack(params[:q])
379
- @supervisors = @q.result.includes(:department, :employees)
380
- end
381
- end
382
- ```
383
-
384
- ... you might set up your form like this...
385
-
386
- ```erb
387
- <%= search_form_for @q do |f| %>
388
- <%= f.label :last_name_cont %>
389
- <%= f.search_field :last_name_cont %>
390
-
391
- <%= f.label :department_title_cont %>
392
- <%= f.search_field :department_title_cont %>
393
-
394
- <%= f.label :employees_first_name_or_employees_last_name_cont %>
395
- <%= f.search_field :employees_first_name_or_employees_last_name_cont %>
396
-
397
- <%= f.submit "search" %>
398
- <% end %>
399
- ...
400
- <%= content_tag :table do %>
401
- <%= content_tag :th, sort_link(@q, :last_name) %>
402
- <%= content_tag :th, sort_link(@q, :department_title) %>
403
- <%= content_tag :th, sort_link(@q, :employees_last_name) %>
404
- <% end %>
405
- ```
8
+ # Introduction
406
9
 
407
- If you have trouble sorting on associations, try using an SQL string with the
408
- pluralized table (`'departments.title'`,`'employees.last_name'`) instead of the
409
- symbolized association (`:department_title)`, `:employees_last_name`).
10
+ Ransack will help you easily add **searching to your Rails application**, without any additional dependencies.
410
11
 
411
- ### Ransack Aliases
12
+ There are advanced searching solutions around, like ElasticSearch or Algolia. **Ransack** will do the job for many Rails websites, without the need to run additional infrastructure or work in a different language. With Ransack you do it all with standard Ruby and ERB.
412
13
 
413
- You can customize the attribute names for your Ransack searches by using a
414
- `ransack_alias`. This is particularly useful for long attribute names that are
415
- necessary when querying associations or multiple columns.
14
+ Ready to move beyond the basics? Use **advanced features** like i18n and extensive configuration options.
416
15
 
417
- ```ruby
418
- class Post < ActiveRecord::Base
419
- belongs_to :author
16
+ Ransack is supported for Rails 7.0, 6.1 on Ruby 3.0 and later.
420
17
 
421
- # Abbreviate :author_first_name_or_author_last_name to :author
422
- ransack_alias :author, :author_first_name_or_author_last_name
423
- end
424
- ```
425
-
426
- Now, rather than using `:author_first_name_or_author_last_name_cont` in your
427
- form, you can simply use `:author_cont`. This serves to produce more expressive
428
- query parameters in your URLs.
429
-
430
- ```erb
431
- <%= search_form_for @q do |f| %>
432
- <%= f.label :author_cont %>
433
- <%= f.search_field :author_cont %>
434
- <% end %>
435
- ```
436
-
437
- ### Search Matchers
438
-
439
- List of all possible predicates
440
-
441
-
442
- | Predicate | Description | Notes |
443
- | ------------- | ------------- |-------- |
444
- | `*_eq` | equal | |
445
- | `*_not_eq` | not equal | |
446
- | `*_matches` | matches with `LIKE` | e.g. `q[email_matches]=%@gmail.com`|
447
- | `*_does_not_match` | does not match with `LIKE` | |
448
- | `*_matches_any` | Matches any | |
449
- | `*_matches_all` | Matches all | |
450
- | `*_does_not_match_any` | Does not match any | |
451
- | `*_does_not_match_all` | Does not match all | |
452
- | `*_lt` | less than | |
453
- | `*_lteq` | less than or equal | |
454
- | `*_gt` | greater than | |
455
- | `*_gteq` | greater than or equal | |
456
- | `*_present` | not null and not empty | Only compatible with string columns. Example: `q[name_present]=1` (SQL: `col is not null AND col != ''`) |
457
- | `*_blank` | is null or empty. | (SQL: `col is null OR col = ''`) |
458
- | `*_null` | is null | |
459
- | `*_not_null` | is not null | |
460
- | `*_in` | match any values in array | e.g. `q[name_in][]=Alice&q[name_in][]=Bob` |
461
- | `*_not_in` | match none of values in array | |
462
- | `*_lt_any` | Less than any | SQL: `col < value1 OR col < value2` |
463
- | `*_lteq_any` | Less than or equal to any | |
464
- | `*_gt_any` | Greater than any | |
465
- | `*_gteq_any` | Greater than or equal to any | |
466
- | `*_matches_any` | `*_does_not_match_any` | same as above but with `LIKE` |
467
- | `*_lt_all` | Less than all | SQL: `col < value1 AND col < value2` |
468
- | `*_lteq_all` | Less than or equal to all | |
469
- | `*_gt_all` | Greater than all | |
470
- | `*_gteq_all` | Greater than or equal to all | |
471
- | `*_matches_all` | Matches all | same as above but with `LIKE` |
472
- | `*_does_not_match_all` | Does not match all | |
473
- | `*_not_eq_all` | none of values in a set | |
474
- | `*_start` | Starts with | SQL: `col LIKE 'value%'` |
475
- | `*_not_start` | Does not start with | |
476
- | `*_start_any` | Starts with any of | |
477
- | `*_start_all` | Starts with all of | |
478
- | `*_not_start_any` | Does not start with any of | |
479
- | `*_not_start_all` | Does not start with all of | |
480
- | `*_end` | Ends with | SQL: `col LIKE '%value'` |
481
- | `*_not_end` | Does not end with | |
482
- | `*_end_any` | Ends with any of | |
483
- | `*_end_all` | Ends with all of | |
484
- | `*_not_end_any` | | |
485
- | `*_not_end_all` | | |
486
- | `*_cont` | Contains value | uses `LIKE` |
487
- | `*_cont_any` | Contains any of | |
488
- | `*_cont_all` | Contains all of | |
489
- | `*_not_cont` | Does not contain |
490
- | `*_not_cont_any` | Does not contain any of | |
491
- | `*_not_cont_all` | Does not contain all of | |
492
- | `*_true` | is true | |
493
- | `*_false` | is false | |
494
-
495
-
496
- (See full list: https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/locale/en.yml#L15 and [wiki](https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching))
497
-
498
- ### Using Ransackers to add custom search functions via Arel
499
-
500
- The main premise behind Ransack is to provide access to
501
- **Arel predicate methods**. Ransack provides special methods, called
502
- _ransackers_, for creating additional search functions via Arel. More
503
- information about `ransacker` methods can be found [here in the wiki](https://github.com/activerecord-hackery/ransack/wiki/Using-Ransackers).
504
- Feel free to contribute working `ransacker` code examples to the wiki!
505
-
506
- ### Problem with DISTINCT selects
507
-
508
- If passed `distinct: true`, `result` will generate a `SELECT DISTINCT` to
509
- avoid returning duplicate rows, even if conditions on a join would otherwise
510
- result in some. It generates the same SQL as calling `uniq` on the relation.
511
-
512
- Please note that for many databases, a sort on an associated table's columns
513
- may result in invalid SQL with `distinct: true` -- in those cases, you
514
- will need to modify the result as needed to allow these queries to work.
515
-
516
- For example, you could call joins and includes on the result which has the
517
- effect of adding those tables columns to the select statement, overcoming
518
- the issue, like so:
519
-
520
- ```ruby
521
- def index
522
- @q = Person.ransack(params[:q])
523
- @people = @q.result(distinct: true)
524
- .includes(:articles)
525
- .joins(:articles)
526
- .page(params[:page])
527
- end
528
- ```
529
-
530
- If the above doesn't help, you can also use ActiveRecord's `select` query
531
- to explicitly add the columns you need, which brute force's adding the
532
- columns you need that your SQL engine is complaining about, you need to
533
- make sure you give all of the columns you care about, for example:
534
-
535
- ```ruby
536
- def index
537
- @q = Person.ransack(params[:q])
538
- @people = @q.result(distinct: true)
539
- .select('people.*, articles.name, articles.description')
540
- .page(params[:page])
541
- end
542
- ```
543
-
544
- Another method to approach this when using Postgresql is to use ActiveRecords's `.includes` in combination with `.group` instead of `distinct: true`.
545
-
546
- For example:
547
- ```ruby
548
- def index
549
- @q = Person.ransack(params[:q])
550
- @people = @q.result
551
- .group('persons.id')
552
- .includes(:articles)
553
- .page(params[:page])
554
- end
555
-
556
- ```
18
+ ## Installation
557
19
 
558
- A final way of last resort is to call `to_a.uniq` on the collection at the end
559
- with the caveat that the de-duping is taking place in Ruby instead of in SQL,
560
- which is potentially slower and uses more memory, and that it may display
561
- awkwardly with pagination if the number of results is greater than the page size.
562
-
563
- For example:
564
-
565
- ```ruby
566
- def index
567
- @q = Person.ransack(params[:q])
568
- @people = @q.result.includes(:articles).page(params[:page]).to_a.uniq
569
- end
570
- ```
571
-
572
- #### `PG::UndefinedFunction: ERROR: could not identify an equality operator for type json`
573
-
574
- If you get the above error while using `distinct: true` that means that
575
- one of the columns that Ransack is selecting is a `json` column.
576
- PostgreSQL does not provide comparison operators for the `json` type. While
577
- it is possible to work around this, in practice it's much better to convert those
578
- to `jsonb`, as [recommended by the PostgreSQL documentation](https://www.postgresql.org/docs/9.6/static/datatype-json.html).
579
-
580
- ### Authorization (whitelisting/blacklisting)
581
-
582
- By default, searching and sorting are authorized on any column of your model
583
- and no class methods/scopes are whitelisted.
584
-
585
- Ransack adds four methods to `ActiveRecord::Base` that you can redefine as
586
- class methods in your models to apply selective authorization:
587
- `ransackable_attributes`, `ransackable_associations`, `ransackable_scopes` and
588
- `ransortable_attributes`.
589
-
590
- Here is how these four methods are implemented in Ransack:
591
-
592
- ```ruby
593
- # `ransackable_attributes` by default returns all column names
594
- # and any defined ransackers as an array of strings.
595
- # For overriding with a whitelist array of strings.
596
- #
597
- def ransackable_attributes(auth_object = nil)
598
- column_names + _ransackers.keys
599
- end
600
-
601
- # `ransackable_associations` by default returns the names
602
- # of all associations as an array of strings.
603
- # For overriding with a whitelist array of strings.
604
- #
605
- def ransackable_associations(auth_object = nil)
606
- reflect_on_all_associations.map { |a| a.name.to_s }
607
- end
608
-
609
- # `ransortable_attributes` by default returns the names
610
- # of all attributes available for sorting as an array of strings.
611
- # For overriding with a whitelist array of strings.
612
- #
613
- def ransortable_attributes(auth_object = nil)
614
- ransackable_attributes(auth_object)
615
- end
616
-
617
- # `ransackable_scopes` by default returns an empty array
618
- # i.e. no class methods/scopes are authorized.
619
- # For overriding with a whitelist array of *symbols*.
620
- #
621
- def ransackable_scopes(auth_object = nil)
622
- []
623
- end
624
- ```
625
-
626
- Any values not returned from these methods will be ignored by Ransack, i.e.
627
- they are not authorized.
628
-
629
- All four methods can receive a single optional parameter, `auth_object`. When
630
- you call the search or ransack method on your model, you can provide a value
631
- for an `auth_object` key in the options hash which can be used by your own
632
- overridden methods.
633
-
634
- Here is an example that puts all this together, adapted from
635
- [this blog post by Ernie Miller](http://erniemiller.org/2012/05/11/why-your-ruby-class-macros-might-suck-mine-did/).
636
- In an `Article` model, add the following `ransackable_attributes` class method
637
- (preferably private):
638
-
639
- ```ruby
640
- class Article < ActiveRecord::Base
641
- def self.ransackable_attributes(auth_object = nil)
642
- if auth_object == :admin
643
- # whitelist all attributes for admin
644
- super
645
- else
646
- # whitelist only the title and body attributes for other users
647
- super & %w(title body)
648
- end
649
- end
650
-
651
- private_class_method :ransackable_attributes
652
- end
653
- ```
654
-
655
- Here is example code for the `articles_controller`:
656
-
657
- ```ruby
658
- class ArticlesController < ApplicationController
659
- def index
660
- @q = Article.ransack(params[:q], auth_object: set_ransack_auth_object)
661
- @articles = @q.result
662
- end
663
-
664
- private
665
-
666
- def set_ransack_auth_object
667
- current_user.admin? ? :admin : nil
668
- end
669
- end
670
- ```
20
+ To install `ransack` and add it to your Gemfile, run
671
21
 
672
- Trying it out in `rails console`:
673
-
674
- ```ruby
675
- > Article
676
- => Article(id: integer, person_id: integer, title: string, body: text)
677
-
678
- > Article.ransackable_attributes
679
- => ["title", "body"]
680
-
681
- > Article.ransackable_attributes(:admin)
682
- => ["id", "person_id", "title", "body"]
683
-
684
- > Article.ransack(id_eq: 1).result.to_sql
685
- => SELECT "articles".* FROM "articles" # Note that search param was ignored!
686
-
687
- > Article.ransack({ id_eq: 1 }, { auth_object: nil }).result.to_sql
688
- => SELECT "articles".* FROM "articles" # Search param still ignored!
689
-
690
- > Article.ransack({ id_eq: 1 }, { auth_object: :admin }).result.to_sql
691
- => SELECT "articles".* FROM "articles" WHERE "articles"."id" = 1
692
- ```
693
-
694
- That's it! Now you know how to whitelist/blacklist various elements in Ransack.
695
-
696
- ### Using Scopes/Class Methods
697
-
698
- Continuing on from the preceding section, searching by scopes requires defining
699
- a whitelist of `ransackable_scopes` on the model class. The whitelist should be
700
- an array of *symbols*. By default, all class methods (e.g. scopes) are ignored.
701
- Scopes will be applied for matching `true` values, or for given values if the
702
- scope accepts a value:
703
-
704
- ```ruby
705
- class Employee < ActiveRecord::Base
706
- scope :activated, ->(boolean = true) { where(active: boolean) }
707
- scope :salary_gt, ->(amount) { where('salary > ?', amount) }
708
-
709
- # Scopes are just syntactical sugar for class methods, which may also be used:
710
-
711
- def self.hired_since(date)
712
- where('start_date >= ?', date)
713
- end
714
-
715
- def self.ransackable_scopes(auth_object = nil)
716
- if auth_object.try(:admin?)
717
- # allow admin users access to all three methods
718
- %i(activated hired_since salary_gt)
719
- else
720
- # allow other users to search on `activated` and `hired_since` only
721
- %i(activated hired_since)
722
- end
723
- end
724
- end
725
-
726
- Employee.ransack({ activated: true, hired_since: '2013-01-01' })
727
-
728
- Employee.ransack({ salary_gt: 100_000 }, { auth_object: current_user })
729
- ```
730
-
731
- In Rails 3 and 4, if the `true` value is being passed via url params or some
732
- other mechanism that will convert it to a string, the true value may not be
733
- passed to the ransackable scope unless you wrap it in an array
734
- (i.e. `activated: ['true']`). Ransack will take care of changing 'true' into a
735
- boolean. This is currently resolved in Rails 5 :smiley:
736
-
737
- However, perhaps you have `user_id: [1]` and you do not want Ransack to convert
738
- 1 into a boolean. (Values sanitized to booleans can be found in the
739
- [constants.rb](https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/constants.rb#L28)).
740
- To turn this off globally, and handle type conversions yourself, set
741
- `sanitize_custom_scope_booleans` to false in an initializer file like
742
- config/initializers/ransack.rb:
743
-
744
- ```ruby
745
- Ransack.configure do |c|
746
- c.sanitize_custom_scope_booleans = false
747
- end
748
- ```
749
-
750
- To turn this off on a per-scope basis Ransack adds the following method to
751
- `ActiveRecord::Base` that you can redefine to selectively override sanitization:
752
-
753
- `ransackable_scopes_skip_sanitize_args`
754
-
755
- Add the scope you wish to bypass this behavior to ransackable_scopes_skip_sanitize_args:
756
-
757
- ```ruby
758
- def ransackable_scopes_skip_sanitize_args
759
- [:scope_to_skip_sanitize_args]
760
- end
761
- ```
762
-
763
- Scopes are a recent addition to Ransack and currently have a few caveats:
764
- First, a scope involving child associations needs to be defined in the parent
765
- table model, not in the child model. Second, scopes with an array as an
766
- argument are not easily usable yet, because the array currently needs to be
767
- wrapped in an array to function (see
768
- [this issue](https://github.com/activerecord-hackery/ransack/issues/404)),
769
- which is not compatible with Ransack form helpers. For this use case, it may be
770
- better for now to use [ransackers](https://github.com/activerecord-hackery/ransack/wiki/Using-Ransackers) instead,
771
- where feasible. Pull requests with solutions and tests are welcome!
772
-
773
- ### Grouping queries by OR instead of AND
774
-
775
- The default `AND` grouping can be changed to `OR` by adding `m: 'or'` to the
776
- query hash.
777
-
778
- You can easily try it in your controller code by changing `params[:q]` in the
779
- `index` action to `params[:q].try(:merge, m: 'or')` as follows:
780
-
781
- ```ruby
782
- def index
783
- @q = Artist.ransack(params[:q].try(:merge, m: 'or'))
784
- @artists = @q.result
785
- end
786
- ```
787
- Normally, if you wanted users to be able to toggle between `AND` and `OR`
788
- query grouping, you would probably set up your search form so that `m` was in
789
- the URL params hash, but here we assigned `m` manually just to try it out
790
- quickly.
791
-
792
- Alternatively, trying it in the Rails console:
793
-
794
- ```ruby
795
- artists = Artist.ransack(name_cont: 'foo', style_cont: 'bar', m: 'or')
796
- => Ransack::Search<class: Artist, base: Grouping <conditions: [
797
- Condition <attributes: ["name"], predicate: cont, values: ["foo"]>,
798
- Condition <attributes: ["style"], predicate: cont, values: ["bar"]>
799
- ], combinator: or>>
800
-
801
- artists.result.to_sql
802
- => "SELECT \"artists\".* FROM \"artists\"
803
- WHERE ((\"artists\".\"name\" ILIKE '%foo%'
804
- OR \"artists\".\"style\" ILIKE '%bar%'))"
805
- ```
806
-
807
- The combinator becomes `or` instead of the default `and`, and the SQL query
808
- becomes `WHERE...OR` instead of `WHERE...AND`.
809
-
810
- This works with associations as well. Imagine an Artist model that has many
811
- Memberships, and many Musicians through Memberships:
812
-
813
- ```ruby
814
- artists = Artist.ransack(name_cont: 'foo', musicians_email_cont: 'bar', m: 'or')
815
- => Ransack::Search<class: Artist, base: Grouping <conditions: [
816
- Condition <attributes: ["name"], predicate: cont, values: ["foo"]>,
817
- Condition <attributes: ["musicians_email"], predicate: cont, values: ["bar"]>
818
- ], combinator: or>>
819
-
820
- artists.result.to_sql
821
- => "SELECT \"artists\".* FROM \"artists\"
822
- LEFT OUTER JOIN \"memberships\"
823
- ON \"memberships\".\"artist_id\" = \"artists\".\"id\"
824
- LEFT OUTER JOIN \"musicians\"
825
- ON \"musicians\".\"id\" = \"memberships\".\"musician_id\"
826
- WHERE ((\"artists\".\"name\" ILIKE '%foo%'
827
- OR \"musicians\".\"email\" ILIKE '%bar%'))"
828
- ```
829
-
830
- ### Using SimpleForm
831
-
832
- If you would like to combine the Ransack and SimpleForm form builders, set the
833
- `RANSACK_FORM_BUILDER` environment variable before Rails boots up, e.g. in
834
- `config/application.rb` before `require 'rails/all'` as shown below (and add
835
- `gem 'simple_form'` in your Gemfile).
836
-
837
- ```ruby
838
- require File.expand_path('../boot', __FILE__)
839
- ENV['RANSACK_FORM_BUILDER'] = '::SimpleForm::FormBuilder'
840
- require 'rails/all'
841
- ```
842
-
843
- ### I18n
844
-
845
- Ransack translation files are available in
846
- [Ransack::Locale](lib/ransack/locale). You may also be interested in one of the
847
- many translations for Ransack available at
848
- http://www.localeapp.com/projects/2999.
849
-
850
- Predicate and attribute translations in forms may be specified as follows (see
851
- the translation files in [Ransack::Locale](lib/ransack/locale) for more examples):
852
-
853
- locales/en.yml:
854
- ```yml
855
- en:
856
- ransack:
857
- asc: ascending
858
- desc: descending
859
- predicates:
860
- cont: contains
861
- not_cont: not contains
862
- start: starts with
863
- end: ends with
864
- gt: greater than
865
- lt: less than
866
- models:
867
- person: Passanger
868
- attributes:
869
- person:
870
- name: Full Name
871
- article:
872
- title: Article Title
873
- body: Main Content
874
- ```
875
-
876
- Attribute names may also be changed globally, or under `activerecord`:
877
-
878
- ```yml
879
- en:
880
- attributes:
881
- model_name:
882
- model_field1: field name1
883
- model_field2: field name2
884
- activerecord:
885
- attributes:
886
- namespace/article:
887
- title: AR Namespaced Title
888
- namespace_article:
889
- title: Old Ransack Namespaced Title
22
+ ```ruby title='Gemfile'
23
+ gem 'ransack'
890
24
  ```
891
25
 
892
- ## Mongoid
893
-
894
- Mongoid support has been moved to its own gem at [ransack-mongoid](https://github.com/activerecord-hackery/ransack-mongoid).
895
- Ransack works with Mongoid in the same way as Active Record, except that with
896
- Mongoid, associations are not currently supported. Demo source code may be found
897
- [here](https://github.com/Zhomart/ransack-mongodb-demo). A `result` method
898
- called on a `ransack` search returns a `Mongoid::Criteria` object:
26
+ ### Bleeding edge
899
27
 
900
- ```ruby
901
- @q = Person.ransack(params[:q])
902
- @people = @q.result # => Mongoid::Criteria
28
+ If you would like to use the latest updates not yet published to RubyGems, use the `main` branch:
903
29
 
904
- # or you can add more Mongoid queries
905
- @people = @q.result.active.order_by(updated_at: -1).limit(10)
30
+ ```ruby title='Gemfile'
31
+ gem 'ransack', :github => 'activerecord-hackery/ransack', :branch => 'main'
906
32
  ```
907
33
 
908
- NOTE: Ransack currently works with either Active Record or Mongoid, but not
909
- both in the same application. If both are present, Ransack will default to
910
- Active Record only. The logic is contained in
911
- `Ransack::Adapters#instantiate_object_mapper` should you need to override it.
912
-
913
- ## Semantic Versioning
34
+ ### Documentation
914
35
 
915
- Ransack attempts to follow semantic versioning in the format of `x.y.z`, where:
36
+ There is [extensive documentation on Ransack](https://activerecord-hackery.github.io/ransack/), which is a [Docusaurus](https://docusaurus.io/) project and run as a GitHub Pages site.
916
37
 
917
- `x` stands for a major version (new features that are not backward-compatible).
918
-
919
- `y` stands for a minor version (new features that are backward-compatible).
38
+ ## Issues tracker
920
39
 
921
- `z` stands for a patch (bug fixes).
40
+ * Before filing an issue, please read the [Contributing Guide](CONTRIBUTING.md).
41
+ * File an issue if a bug is caused by Ransack, is new (has not already been reported), and _can be reproduced from the information you provide_.
42
+ * Please consider adding a branch with a failing spec describing the problem.
43
+ * Contributions are welcome. :smiley:
44
+ * Please do not use the issue tracker for personal support requests. Stack Overflow or [GitHub Discussions](https://github.com/activerecord-hackery/ransack/discussions) is a better place for that where a wider community can help you!
922
45
 
923
- In other words: `Major.Minor.Patch`.
924
46
 
925
47
  ## Contributions
926
48
 
927
49
  To support the project:
928
50
 
51
+ * Consider supporting us via [Open Collective](https://opencollective.com/ransack/backers/badge.svg)
929
52
  * Use Ransack in your apps, and let us know if you encounter anything that's
930
53
  broken or missing. A failing spec to demonstrate the issue is awesome. A pull
931
54
  request with passing tests is even better!
932
55
  * Before filing an issue or pull request, be sure to read and follow the
933
56
  [Contributing Guide](CONTRIBUTING.md).
934
- * Please use Stack Overflow or other sites for questions or discussion not
57
+ * Please use Stack Overflow or [GitHub Discussions](https://github.com/activerecord-hackery/ransack/discussions) for questions or discussion not
935
58
  directly related to bug reports, pull requests, or documentation improvements.
936
- * Spread the word on Twitter, Facebook, and elsewhere if Ransack's been useful
59
+ * Spread the word on social media if Ransack's been useful
937
60
  to you. The more people who are using the project, the quicker we can find and
938
61
  fix bugs!
939
62
 
940
63
  ## Contributors
941
64
 
65
+ Ransack was created by [Ernie Miller](http://twitter.com/erniemiller) and is developed and maintained by:
66
+ * [Sean Carroll](https://github.com/scarroll32)
67
+ * [Deivid Rodriguez](https://github.com/deivid-rodriguez)
68
+ * [Greg Molnar](https://github.com/gregmolnar)
69
+ * [A great group of contributors](https://github.com/activerecord-hackery/ransack/graphs/contributors).
70
+ - Ransack's logo is designed by [Anıl Kılıç](https://github.com/anilkilic).
71
+
72
+ Alumni Maintainers
73
+ - [Jon Atack](http://twitter.com/jonatack)
74
+ - [Ryan Bigg](http://twitter.com/ryanbigg)
75
+
942
76
  This project exists thanks to all the people who contribute. <img src="https://opencollective.com/ransack/contributors.svg?width=890&button=false" />
943
77
 
944
78
 
@@ -946,22 +80,20 @@ This project exists thanks to all the people who contribute. <img src="https://o
946
80
 
947
81
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/ransack#backer)]
948
82
 
949
- <a href="https://opencollective.com/ransack#backers" target="_blank"><img src="https://opencollective.com/ransack/backers.svg?width=890"></a>
83
+ <a href="https://opencollective.com/ransack#backers" target="_blank"><img src="https://opencollective.com/ransack/backers.svg?width=890" /></a>
950
84
 
951
85
 
952
86
  ## Sponsors
953
87
 
954
88
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/ransack#sponsor)]
955
89
 
956
- <a href="https://opencollective.com/ransack/sponsor/0/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/0/avatar.svg"></a>
957
- <a href="https://opencollective.com/ransack/sponsor/1/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/1/avatar.svg"></a>
958
- <a href="https://opencollective.com/ransack/sponsor/2/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/2/avatar.svg"></a>
959
- <a href="https://opencollective.com/ransack/sponsor/3/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/3/avatar.svg"></a>
960
- <a href="https://opencollective.com/ransack/sponsor/4/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/4/avatar.svg"></a>
961
- <a href="https://opencollective.com/ransack/sponsor/5/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/5/avatar.svg"></a>
962
- <a href="https://opencollective.com/ransack/sponsor/6/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/6/avatar.svg"></a>
963
- <a href="https://opencollective.com/ransack/sponsor/7/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/7/avatar.svg"></a>
964
- <a href="https://opencollective.com/ransack/sponsor/8/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/8/avatar.svg"></a>
965
- <a href="https://opencollective.com/ransack/sponsor/9/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/9/avatar.svg"></a>
966
-
967
-
90
+ <a href="https://opencollective.com/ransack/sponsor/0/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/0/avatar.svg" /></a>
91
+ <a href="https://opencollective.com/ransack/sponsor/1/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/1/avatar.svg" /></a>
92
+ <a href="https://opencollective.com/ransack/sponsor/2/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/2/avatar.svg" /></a>
93
+ <a href="https://opencollective.com/ransack/sponsor/3/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/3/avatar.svg" /></a>
94
+ <a href="https://opencollective.com/ransack/sponsor/4/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/4/avatar.svg" /></a>
95
+ <a href="https://opencollective.com/ransack/sponsor/5/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/5/avatar.svg" /></a>
96
+ <a href="https://opencollective.com/ransack/sponsor/6/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/6/avatar.svg" /></a>
97
+ <a href="https://opencollective.com/ransack/sponsor/7/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/7/avatar.svg" /></a>
98
+ <a href="https://opencollective.com/ransack/sponsor/8/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/8/avatar.svg" /></a>
99
+ <a href="https://opencollective.com/ransack/sponsor/9/website" target="_blank"><img src="https://opencollective.com/ransack/sponsor/9/avatar.svg" /></a>