ransack 4.1.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/polyamorous/activerecord/join_association_7_2.rb +55 -0
- data/lib/polyamorous/polyamorous.rb +5 -1
- data/lib/ransack/adapters/active_record/context.rb +32 -5
- data/lib/ransack/constants.rb +1 -1
- data/lib/ransack/context.rb +7 -4
- data/lib/ransack/helpers/form_builder.rb +6 -7
- data/lib/ransack/helpers/form_helper.rb +86 -20
- data/lib/ransack/invalid_search_error.rb +3 -0
- data/lib/ransack/locale/ja.yml +51 -51
- data/lib/ransack/locale/ko.yml +70 -0
- data/lib/ransack/locale/uk.yml +72 -0
- data/lib/ransack/nodes/condition.rb +39 -7
- data/lib/ransack/nodes/grouping.rb +1 -1
- data/lib/ransack/nodes/sort.rb +1 -1
- data/lib/ransack/nodes/value.rb +9 -1
- data/lib/ransack/search.rb +4 -3
- data/lib/ransack/version.rb +1 -1
- data/lib/ransack.rb +9 -0
- data/spec/polyamorous/join_association_spec.rb +0 -1
- data/spec/polyamorous/join_dependency_spec.rb +0 -1
- data/spec/ransack/adapters/active_record/base_spec.rb +106 -3
- data/spec/ransack/adapters/active_record/context_spec.rb +72 -0
- data/spec/ransack/helpers/form_builder_spec.rb +0 -2
- data/spec/ransack/helpers/form_helper_spec.rb +219 -5
- data/spec/ransack/nodes/condition_spec.rb +230 -0
- data/spec/ransack/nodes/grouping_spec.rb +2 -2
- data/spec/ransack/nodes/value_spec.rb +12 -1
- data/spec/ransack/predicate_spec.rb +16 -9
- data/spec/ransack/search_spec.rb +121 -1
- data/spec/ransack/translate_spec.rb +0 -1
- data/spec/spec_helper.rb +2 -3
- data/spec/support/schema.rb +42 -0
- metadata +17 -86
- data/.github/FUNDING.yml +0 -3
- data/.github/SECURITY.md +0 -12
- data/.github/workflows/codeql.yml +0 -72
- data/.github/workflows/cronjob.yml +0 -99
- data/.github/workflows/deploy.yml +0 -35
- data/.github/workflows/rubocop.yml +0 -20
- data/.github/workflows/test-deploy.yml +0 -29
- data/.github/workflows/test.yml +0 -131
- data/.gitignore +0 -7
- data/.nojekyll +0 -0
- data/.rubocop.yml +0 -50
- data/CHANGELOG.md +0 -1176
- data/CONTRIBUTING.md +0 -171
- data/Gemfile +0 -53
- data/Rakefile +0 -24
- data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +0 -78
- data/bug_report_templates/test-ransacker-arel-present-predicate.rb +0 -75
- data/docs/.gitignore +0 -19
- data/docs/.nojekyll +0 -0
- data/docs/babel.config.js +0 -3
- data/docs/blog/2022-03-27-ransack-3.0.0.md +0 -20
- data/docs/docs/getting-started/_category_.json +0 -4
- data/docs/docs/getting-started/advanced-mode.md +0 -46
- data/docs/docs/getting-started/configuration.md +0 -47
- data/docs/docs/getting-started/search-matches.md +0 -67
- data/docs/docs/getting-started/simple-mode.md +0 -288
- data/docs/docs/getting-started/sorting.md +0 -71
- data/docs/docs/getting-started/using-predicates.md +0 -282
- data/docs/docs/going-further/_category_.json +0 -4
- data/docs/docs/going-further/acts-as-taggable-on.md +0 -114
- data/docs/docs/going-further/associations.md +0 -70
- data/docs/docs/going-further/custom-predicates.md +0 -52
- data/docs/docs/going-further/documentation.md +0 -43
- data/docs/docs/going-further/exporting-to-csv.md +0 -49
- data/docs/docs/going-further/external-guides.md +0 -57
- data/docs/docs/going-further/form-customisation.md +0 -63
- data/docs/docs/going-further/i18n.md +0 -53
- data/docs/docs/going-further/img/create_release.png +0 -0
- data/docs/docs/going-further/merging-searches.md +0 -41
- data/docs/docs/going-further/other-notes.md +0 -428
- data/docs/docs/going-further/polymorphic-search.md +0 -46
- data/docs/docs/going-further/ransackers.md +0 -331
- data/docs/docs/going-further/release_process.md +0 -36
- data/docs/docs/going-further/saving-queries.md +0 -82
- data/docs/docs/going-further/searching-postgres.md +0 -57
- data/docs/docs/going-further/wiki-contributors.md +0 -82
- data/docs/docs/intro.md +0 -99
- data/docs/docusaurus.config.js +0 -120
- data/docs/package.json +0 -42
- data/docs/sidebars.js +0 -31
- data/docs/src/components/HomepageFeatures/index.js +0 -64
- data/docs/src/components/HomepageFeatures/styles.module.css +0 -11
- data/docs/src/css/custom.css +0 -39
- data/docs/src/pages/index.module.css +0 -23
- data/docs/src/pages/markdown-page.md +0 -7
- data/docs/static/.nojekyll +0 -0
- data/docs/static/img/docusaurus.png +0 -0
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/logo.svg +0 -1
- data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
- data/docs/static/img/tutorial/localeDropdown.png +0 -0
- data/docs/static/img/undraw_docusaurus_mountain.svg +0 -171
- data/docs/static/img/undraw_docusaurus_react.svg +0 -170
- data/docs/static/img/undraw_docusaurus_tree.svg +0 -40
- data/docs/static/logo/ransack-h.png +0 -0
- data/docs/static/logo/ransack-h.svg +0 -34
- data/docs/static/logo/ransack-v.png +0 -0
- data/docs/static/logo/ransack-v.svg +0 -34
- data/docs/static/logo/ransack.png +0 -0
- data/docs/static/logo/ransack.svg +0 -21
- data/docs/yarn.lock +0 -8879
- data/ransack.gemspec +0 -26
data/CONTRIBUTING.md
DELETED
@@ -1,171 +0,0 @@
|
|
1
|
-
# Contributing to Ransack
|
2
|
-
|
3
|
-
Please take a moment to review this document to make contributing easy and
|
4
|
-
effective for everyone involved!
|
5
|
-
|
6
|
-
Ransack is an open source project and we encourage contributions.
|
7
|
-
|
8
|
-
Please do not use the issue tracker for personal support requests. Stack
|
9
|
-
Overflow is a better place for that where a wider community can help you!
|
10
|
-
|
11
|
-
## Filing an issue
|
12
|
-
|
13
|
-
Good issue reports are extremely helpful! Please only open an issue if a bug
|
14
|
-
is caused by Ransack, is new (has not already been reported), and can be
|
15
|
-
reproduced from the information you provide.
|
16
|
-
|
17
|
-
Steps:
|
18
|
-
|
19
|
-
1. **Use the GitHub issue search** — check if the issue has already been
|
20
|
-
reported.
|
21
|
-
|
22
|
-
2. **Check if the issue has been fixed** — try to reproduce it using the
|
23
|
-
`main` branch in the repository.
|
24
|
-
|
25
|
-
3. **Isolate the real problem** — make sure the issue is really a bug in
|
26
|
-
Ransack and not in your code or another gem.
|
27
|
-
|
28
|
-
4. **Report the issue** by providing the link to a self-contained
|
29
|
-
gist like [this](https://github.com/activerecord-hackery/ransack/blob/main/bug_report_templates/test-ransack-scope-and-column-same-name.rb) or
|
30
|
-
[this](https://github.com/activerecord-hackery/ransack/blob/main/bug_report_templates/test-ransacker-arel-present-predicate.rb). Please use
|
31
|
-
these code examples as a bug-report template for your Ransack issue!
|
32
|
-
|
33
|
-
If you do not provide a self-contained gist and would like your issue to be reviewed, do provide at a minimum:
|
34
|
-
|
35
|
-
* A comprehensive list of steps to reproduce the issue, or even better, a
|
36
|
-
passing/failing test spec.
|
37
|
-
* Whether you are using Ransack through another gem like ActiveAdmin,
|
38
|
-
SimpleForm, etc.
|
39
|
-
* The versions of Ruby, Rails, Ransack and the database.
|
40
|
-
* Any relevant stack traces ("Full trace" preferred).
|
41
|
-
|
42
|
-
Issues filed without the above information or that remain open without activity
|
43
|
-
for 14 days will be closed. They can be re-opened if actionable information to reproduce the issue is provided.
|
44
|
-
|
45
|
-
## Pull requests
|
46
|
-
|
47
|
-
We gladly accept pull requests to fix bugs and, in some circumstances, add new
|
48
|
-
features to Ransack. If you'd like to contribute and wonder what would be
|
49
|
-
helpful, simply run a search for "FIXME" and "TODO" on the codebase :smiley:
|
50
|
-
|
51
|
-
If you're new to contributing to open source, welcome! It can seem scary, so
|
52
|
-
here is a [great blog post to help you get started]
|
53
|
-
(http://robots.thoughtbot.com/8-new-steps-for-fixing-other-peoples-code),
|
54
|
-
step by step.
|
55
|
-
|
56
|
-
Before issuing a pull request, please make sure that all specs are passing,
|
57
|
-
that any new features have test coverage, and that anything that breaks
|
58
|
-
backward compatibility has a very good reason for doing so.
|
59
|
-
|
60
|
-
Here's a quick guide:
|
61
|
-
|
62
|
-
1. Fork the repo.
|
63
|
-
|
64
|
-
2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
|
65
|
-
|
66
|
-
3. Install the development dependencies by running `bundle install`.
|
67
|
-
To install rails other than latest (set in Gemfile): `RAILS='6-1-stable' bundle install`
|
68
|
-
|
69
|
-
4. Begin by running the tests. We only take pull requests with passing tests,
|
70
|
-
and it's great to know that you have a clean slate:
|
71
|
-
|
72
|
-
```sh
|
73
|
-
bundle exec rake spec
|
74
|
-
```
|
75
|
-
|
76
|
-
The test suite runs by default with SQLite3. To run the test suite with PostgreSQL or MySQL, use:
|
77
|
-
|
78
|
-
```sh
|
79
|
-
DB=pg bundle exec rake spec
|
80
|
-
DB=mysql bundle exec rake spec
|
81
|
-
```
|
82
|
-
|
83
|
-
A one-liner to run all three
|
84
|
-
|
85
|
-
```sh
|
86
|
-
bundle exec rake spec && DB=pg bundle exec rake spec && DB=mysql bundle exec rake spec
|
87
|
-
```
|
88
|
-
|
89
|
-
For Postgres and MySQL, databases are expected to exist, called 'ransack'. To create use these commands (assuming OS X and Homebrew):
|
90
|
-
|
91
|
-
### Postgres
|
92
|
-
|
93
|
-
```sh
|
94
|
-
createdb ransack
|
95
|
-
```
|
96
|
-
|
97
|
-
### MySQL
|
98
|
-
|
99
|
-
```sh
|
100
|
-
mysql -u root
|
101
|
-
mysql> create database ransack;
|
102
|
-
```
|
103
|
-
|
104
|
-
The test suite runs by default
|
105
|
-
|
106
|
-
To run only the tests in a particular file: `bundle exec rspec <path/to/filename>`
|
107
|
-
|
108
|
-
```sh
|
109
|
-
bundle exec rspec spec/ransack/search_spec.rb
|
110
|
-
```
|
111
|
-
|
112
|
-
To run a single test in that file: `bundle exec rspec <path/to/filename> -e "test name"`
|
113
|
-
|
114
|
-
```sh
|
115
|
-
bundle exec rspec spec/ransack/search_spec.rb -e "accepts a context option"
|
116
|
-
```
|
117
|
-
|
118
|
-
5. Add tests for your changes. Only refactoring and documentation changes
|
119
|
-
require no new tests. If you are adding functionality or fixing a bug, we
|
120
|
-
need a test!
|
121
|
-
|
122
|
-
6. Make the tests pass.
|
123
|
-
|
124
|
-
7. Update the Change Log. If you are adding new functionality, document it in
|
125
|
-
the README.
|
126
|
-
|
127
|
-
8. Make sure git knows your name and email address in your `~/.gitconfig` file:
|
128
|
-
|
129
|
-
```sh
|
130
|
-
git config --global user.name "Your Name"
|
131
|
-
git config --global user.email "contributor@example.com"
|
132
|
-
```
|
133
|
-
|
134
|
-
9. Commit your changes (`git commit -am 'Add feature/fix bug/improve docs'`).
|
135
|
-
If your pull request only contains documentation changes, please remember
|
136
|
-
to add `[skip ci]` to the beginning of your commit message so the CI
|
137
|
-
test suite doesn't :runner: needlessly.
|
138
|
-
|
139
|
-
10. If necessary, rebase your commits into logical chunks, without errors. To
|
140
|
-
interactively rebase and cherry-pick from, say, the last 10 commits:
|
141
|
-
`git rebase -i HEAD~10`, then `git push -f`.
|
142
|
-
|
143
|
-
11. Push the branch up to your fork on GitHub
|
144
|
-
(`git push origin my-new-feature`) and from GitHub submit a pull request to
|
145
|
-
Ransack's `main` branch.
|
146
|
-
|
147
|
-
At this point you're waiting on us. We like to at least comment on, if not
|
148
|
-
accept, pull requests within three business days (and, typically, one business
|
149
|
-
day). We may suggest some changes or improvements or alternatives.
|
150
|
-
|
151
|
-
Some things that will increase the chance that your pull request is accepted:
|
152
|
-
|
153
|
-
* Include tests that fail without your code, and pass with it.
|
154
|
-
* Update the README, the change log, the documentation... anything that is
|
155
|
-
affected by your contribution.
|
156
|
-
* Use idiomatic Ruby and follow the syntax conventions below.
|
157
|
-
|
158
|
-
Syntax:
|
159
|
-
|
160
|
-
* Indent with two spaces, no tabs.
|
161
|
-
* 80 characters per line.
|
162
|
-
* No trailing whitespace. Blank lines should not have any space.
|
163
|
-
* Prefer `&&`/`||` over `and`/`or`.
|
164
|
-
* `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
|
165
|
-
* `a = b` and not `a=b`.
|
166
|
-
* `a_method { |block| ... }` and not `a_method { | block | ... }` or
|
167
|
-
`a_method{|block| ...}`.
|
168
|
-
* Prefer simplicity, readability, and maintainability over terseness.
|
169
|
-
* Follow the conventions you see used in the code already.
|
170
|
-
|
171
|
-
And in case we didn't emphasize it enough: We love tests!
|
data/Gemfile
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec
|
3
|
-
|
4
|
-
gem 'rake'
|
5
|
-
|
6
|
-
rails = ENV['RAILS'] || '7-1-stable'
|
7
|
-
|
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
|
16
|
-
|
17
|
-
gem 'faker'
|
18
|
-
gem 'sqlite3'
|
19
|
-
gem 'pg'
|
20
|
-
gem 'pry'
|
21
|
-
gem 'byebug'
|
22
|
-
|
23
|
-
case rails
|
24
|
-
when /\// # A path
|
25
|
-
gem 'activesupport', path: "#{rails}/activesupport"
|
26
|
-
gem 'activemodel', path: "#{rails}/activemodel"
|
27
|
-
gem 'activerecord', path: "#{rails}/activerecord", require: false
|
28
|
-
gem 'actionpack', path: "#{rails}/actionpack"
|
29
|
-
gem 'actionview', path: "#{rails}/actionview"
|
30
|
-
when /^v/ # A tagged version
|
31
|
-
git 'https://github.com/rails/rails.git', tag: rails do
|
32
|
-
gem 'activesupport'
|
33
|
-
gem 'activemodel'
|
34
|
-
gem 'activerecord', require: false
|
35
|
-
gem 'actionpack'
|
36
|
-
end
|
37
|
-
else
|
38
|
-
git 'https://github.com/rails/rails.git', branch: rails do
|
39
|
-
gem 'activesupport'
|
40
|
-
gem 'activemodel'
|
41
|
-
gem 'activerecord', require: false
|
42
|
-
gem 'actionpack'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
gem 'mysql2'
|
46
|
-
|
47
|
-
group :test do
|
48
|
-
gem 'machinist', '~> 1.0.6'
|
49
|
-
gem 'rspec'
|
50
|
-
gem 'simplecov', require: false
|
51
|
-
end
|
52
|
-
|
53
|
-
gem 'rubocop', require: false
|
data/Rakefile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
Bundler::GemHelper.install_tasks
|
5
|
-
|
6
|
-
RSpec::Core::RakeTask.new(:spec) do |rspec|
|
7
|
-
ENV['SPEC'] = 'spec/ransack/**/*_spec.rb'
|
8
|
-
# With Rails 3, using `--backtrace` raises 'invalid option' when testing.
|
9
|
-
# With Rails 4 and 5 it can be uncommented to see the backtrace:
|
10
|
-
#
|
11
|
-
# rspec.rspec_opts = ['--backtrace']
|
12
|
-
end
|
13
|
-
|
14
|
-
task :default do
|
15
|
-
Rake::Task["spec"].invoke
|
16
|
-
end
|
17
|
-
|
18
|
-
desc "Open an irb session with Ransack and the sample data used in specs"
|
19
|
-
task :console do
|
20
|
-
require 'pry'
|
21
|
-
require File.expand_path('../spec/console.rb', __FILE__)
|
22
|
-
ARGV.clear
|
23
|
-
Pry.start
|
24
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# test-ransack-scope-and-column-same-name.rb
|
2
|
-
|
3
|
-
# This is a stand-alone test case.
|
4
|
-
|
5
|
-
# Run it in your console with: `ruby test-ransack-scope-and-column-same-name.rb`
|
6
|
-
|
7
|
-
# If you change the gem dependencies, run it with:
|
8
|
-
# `rm gemfile* && ruby test-ransack-scope-and-column-same-name.rb`
|
9
|
-
|
10
|
-
unless File.exist?('Gemfile')
|
11
|
-
File.write('Gemfile', <<-GEMFILE)
|
12
|
-
source 'https://rubygems.org'
|
13
|
-
|
14
|
-
# Rails master
|
15
|
-
gem 'rails', github: 'rails/rails', branch: '7-1-stable'
|
16
|
-
|
17
|
-
# Rails last release
|
18
|
-
# gem 'rails'
|
19
|
-
|
20
|
-
gem 'sqlite3'
|
21
|
-
gem 'ransack', github: 'activerecord-hackery/ransack'
|
22
|
-
GEMFILE
|
23
|
-
|
24
|
-
system 'bundle install'
|
25
|
-
end
|
26
|
-
|
27
|
-
require 'bundler'
|
28
|
-
Bundler.setup(:default)
|
29
|
-
|
30
|
-
require 'active_record'
|
31
|
-
require 'minitest/autorun'
|
32
|
-
require 'logger'
|
33
|
-
require 'ransack'
|
34
|
-
|
35
|
-
# This connection will do for database-independent bug reports.
|
36
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
37
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
38
|
-
|
39
|
-
# Display versions.
|
40
|
-
message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{
|
41
|
-
::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{
|
42
|
-
::ActiveRecord::Base.connection.adapter_name}"
|
43
|
-
line = '=' * message.length
|
44
|
-
puts line, message, line
|
45
|
-
|
46
|
-
ActiveRecord::Schema.define do
|
47
|
-
create_table :users, force: true do |t|
|
48
|
-
t.boolean :active, null: false, default: true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class User < ActiveRecord::Base
|
53
|
-
scope :activated, -> (boolean = true) { where(active: boolean) }
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def self.ransackable_scopes(auth_object = nil)
|
58
|
-
%i(activated)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class BugTest < Minitest::Test
|
63
|
-
def test_activated_scope_equals_true
|
64
|
-
sql = User.ransack({ activated: true }).result.to_sql
|
65
|
-
puts sql
|
66
|
-
assert_equal(
|
67
|
-
"SELECT \"users\".* FROM \"users\" WHERE \"users\".\"active\" = 1", sql
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_activated_scope_equals_false
|
72
|
-
sql = User.ransack({ activated: false }).result.to_sql
|
73
|
-
puts sql
|
74
|
-
assert_equal(
|
75
|
-
"SELECT \"users\".* FROM \"users\"", sql
|
76
|
-
)
|
77
|
-
end
|
78
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# test-ransacker-arel-present-predicate.rb
|
2
|
-
|
3
|
-
# Run it in your console with: `ruby test-ransacker-arel-present-predicate.rb`
|
4
|
-
|
5
|
-
# If you change the gem dependencies, run it with:
|
6
|
-
# `rm gemfile* && ruby test-ransacker-arel-present-predicate.rb`
|
7
|
-
|
8
|
-
unless File.exist?('Gemfile')
|
9
|
-
File.write('Gemfile', <<-GEMFILE)
|
10
|
-
source 'https://rubygems.org'
|
11
|
-
|
12
|
-
# Rails master
|
13
|
-
gem 'rails', github: 'rails/rails', branch: '7-1-stable'
|
14
|
-
|
15
|
-
# Rails last release
|
16
|
-
# gem 'rails'
|
17
|
-
|
18
|
-
gem 'sqlite3'
|
19
|
-
gem 'ransack', github: 'activerecord-hackery/ransack'
|
20
|
-
GEMFILE
|
21
|
-
|
22
|
-
system 'bundle install'
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'bundler'
|
26
|
-
Bundler.setup(:default)
|
27
|
-
|
28
|
-
require 'active_record'
|
29
|
-
require 'minitest/autorun'
|
30
|
-
require 'logger'
|
31
|
-
require 'ransack'
|
32
|
-
|
33
|
-
# This connection will do for database-independent bug reports.
|
34
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
35
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
36
|
-
|
37
|
-
# Display versions.
|
38
|
-
message = "Running test case with Ruby #{RUBY_VERSION}, Active Record #{
|
39
|
-
::ActiveRecord::VERSION::STRING}, Arel #{Arel::VERSION} and #{
|
40
|
-
::ActiveRecord::Base.connection.adapter_name}"
|
41
|
-
line = '=' * message.length
|
42
|
-
puts line, message, line
|
43
|
-
|
44
|
-
ActiveRecord::Schema.define do
|
45
|
-
create_table :projects, force: true do |t|
|
46
|
-
t.string :name
|
47
|
-
t.string :number
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Project < ActiveRecord::Base
|
52
|
-
ransacker :name do
|
53
|
-
Arel.sql('projects.name')
|
54
|
-
end
|
55
|
-
|
56
|
-
ransacker :number do |parent|
|
57
|
-
parent.table[:number]
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.ransackable_attributes(_auth_object = nil)
|
61
|
-
["name", "number"]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class BugTest < Minitest::Test
|
66
|
-
def test_ransackers
|
67
|
-
sql = Project.ransack({ number_present: 1 }).result.to_sql
|
68
|
-
puts sql
|
69
|
-
assert_equal "SELECT \"projects\".* FROM \"projects\" WHERE (\"projects\".\"number\" IS NOT NULL AND \"projects\".\"number\" != '')", sql
|
70
|
-
|
71
|
-
sql = Project.ransack({ name_present: 1 }).result.to_sql
|
72
|
-
puts sql
|
73
|
-
assert_equal "SELECT \"projects\".* FROM \"projects\" WHERE (projects.name IS NOT NULL AND projects.name != '')", sql
|
74
|
-
end
|
75
|
-
end
|
data/docs/.gitignore
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# Dependencies
|
2
|
-
/node_modules
|
3
|
-
|
4
|
-
# Production
|
5
|
-
/build
|
6
|
-
|
7
|
-
# Generated files
|
8
|
-
.docusaurus
|
9
|
-
.cache-loader
|
10
|
-
|
11
|
-
# Misc
|
12
|
-
.DS_Store
|
13
|
-
.env.local
|
14
|
-
.env.development.local
|
15
|
-
.env.test.local
|
16
|
-
.env.production.local
|
17
|
-
|
18
|
-
yarn-debug.log*
|
19
|
-
yarn-error.log*
|
data/docs/.nojekyll
DELETED
File without changes
|
data/docs/babel.config.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
---
|
2
|
-
slug: ransack-3-0-0
|
3
|
-
title: Ransack 3.0.0
|
4
|
-
authors:
|
5
|
-
name: Sean Carroll
|
6
|
-
title: Ransack Core Team
|
7
|
-
tags: [ransack, release]
|
8
|
-
---
|
9
|
-
|
10
|
-
Ransack has been a part of many Rubyists toolboxes for years and 3.0.0 is a major release. We have a number of new features and one breaking change. As part of 3.0.0, we decided to launch this documentation website, merging in the Wiki and the content from the README.
|
11
|
-
|
12
|
-
With 3.0.0 we are hoping to re-energise the community, we need help on closing out old issues, refactoring the codebase and even some design work.
|
13
|
-
|
14
|
-
I also wanted to let you know that Ernie Miller (creator of Ransack) has decided to leave the project completely, he has this message for the community:
|
15
|
-
|
16
|
-
> While my own personal development efforts have been spent elsewhere as of late, I'm keenly aware of how many people still depend on some of the software I originally wrote all those years ago.
|
17
|
-
|
18
|
-
> That's why I'm grateful to be able to step away from the ActiveRecord Hackery organization (and, specifically, maintenance of Ransack) without impacting those users. I'm thankful that Sean, David, Greg, and others will continue to support users, and wish them the best as they move forward without me!
|
19
|
-
|
20
|
-
Please join me in thanking Ernie for bringing Ransack to life, I personally think it is one of the most amazing Rails libraries out there.
|
@@ -1,46 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 2
|
3
|
-
title: Advanced Mode
|
4
|
-
---
|
5
|
-
|
6
|
-
|
7
|
-
"Advanced" searches Rails's nested attributes functionality in order to
|
8
|
-
generate complex queries with nested AND/OR groupings, etc. This takes a bit
|
9
|
-
more work but can generate some pretty cool search interfaces that put a lot of
|
10
|
-
power in the hands of your users.
|
11
|
-
|
12
|
-
A notable drawback with these searches is
|
13
|
-
that the increased size of the parameter string will typically force you to use
|
14
|
-
the HTTP POST method instead of GET.
|
15
|
-
|
16
|
-
|
17
|
-
## Tweak your routes
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
resources :people do
|
21
|
-
collection do
|
22
|
-
match 'search' => 'people#search', via: [:get, :post], as: :search
|
23
|
-
end
|
24
|
-
end
|
25
|
-
```
|
26
|
-
|
27
|
-
## Add a controller action
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
def search
|
31
|
-
index
|
32
|
-
render :index
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
|
-
## Update your form
|
37
|
-
|
38
|
-
```erb
|
39
|
-
<%= search_form_for @q, url: search_people_path,
|
40
|
-
html: { method: :post } do |f| %>
|
41
|
-
```
|
42
|
-
|
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
|
-
construct much more complex search forms, such as the one on the
|
45
|
-
[demo app](http://ransack-demo.herokuapp.com/users/advanced_search)
|
46
|
-
(source code [here](https://github.com/activerecord-hackery/ransack_demo)).
|
@@ -1,47 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 3
|
3
|
-
title: Configuration
|
4
|
-
---
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
Ransack may be easily configured. The best place to put configuration is in an initializer file at `config/initializers/ransack.rb`, containing code such as:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
Ransack.configure do |config|
|
12
|
-
|
13
|
-
# Change default search parameter key name.
|
14
|
-
# Default key name is :q
|
15
|
-
config.search_key = :query
|
16
|
-
|
17
|
-
# Raise errors if a query contains an unknown predicate or attribute.
|
18
|
-
# Default is true (do not raise error on unknown conditions).
|
19
|
-
config.ignore_unknown_conditions = false
|
20
|
-
|
21
|
-
# Globally display sort links without the order indicator arrow.
|
22
|
-
# Default is false (sort order indicators are displayed).
|
23
|
-
# This can also be configured individually in each sort link (see the README).
|
24
|
-
config.hide_sort_order_indicators = true
|
25
|
-
|
26
|
-
end
|
27
|
-
```
|
28
|
-
|
29
|
-
## Custom search parameter key name
|
30
|
-
|
31
|
-
Sometimes there are situations when the default search parameter name cannot be used, for instance,
|
32
|
-
if there are two searches on one page. Another name may be set using the `search_key` option in the `ransack` or `search` methods in the controller, and in the `@search_form_for` method in the view.
|
33
|
-
|
34
|
-
### In the controller
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
@search = Log.ransack(params[:log_search], search_key: :log_search)
|
38
|
-
# or
|
39
|
-
@search = Log.search(params[:log_search], search_key: :log_search)
|
40
|
-
```
|
41
|
-
|
42
|
-
### In the view
|
43
|
-
|
44
|
-
```erb
|
45
|
-
<%= f.search_form_for @search, as: :log_search %>
|
46
|
-
<%= sort_link(@search) %>
|
47
|
-
```
|
@@ -1,67 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: Search Matchers
|
3
|
-
---
|
4
|
-
|
5
|
-
### Search Matchers
|
6
|
-
|
7
|
-
List of all possible predicates
|
8
|
-
|
9
|
-
|
10
|
-
| Predicate | Description | Notes |
|
11
|
-
| ------------- | ------------- |-------- |
|
12
|
-
| `*_eq` | equal | |
|
13
|
-
| `*_not_eq` | not equal | |
|
14
|
-
| `*_matches` | matches with `LIKE` | e.g. `q[email_matches]=%@gmail.com`|
|
15
|
-
| `*_does_not_match` | does not match with `LIKE` | |
|
16
|
-
| `*_matches_any` | Matches any | |
|
17
|
-
| `*_matches_all` | Matches all | |
|
18
|
-
| `*_does_not_match_any` | Does not match any | |
|
19
|
-
| `*_does_not_match_all` | Does not match all | |
|
20
|
-
| `*_lt` | less than | |
|
21
|
-
| `*_lteq` | less than or equal | |
|
22
|
-
| `*_gt` | greater than | |
|
23
|
-
| `*_gteq` | greater than or equal | |
|
24
|
-
| `*_present` | not null and not empty | Only compatible with string columns. Example: `q[name_present]=1` (SQL: `col is not null AND col != ''`) |
|
25
|
-
| `*_blank` | is null or empty. | (SQL: `col is null OR col = ''`) |
|
26
|
-
| `*_null` | is null | |
|
27
|
-
| `*_not_null` | is not null | |
|
28
|
-
| `*_in` | match any values in array | e.g. `q[name_in][]=Alice&q[name_in][]=Bob` |
|
29
|
-
| `*_not_in` | match none of values in array | |
|
30
|
-
| `*_lt_any` | Less than any | SQL: `col < value1 OR col < value2` |
|
31
|
-
| `*_lteq_any` | Less than or equal to any | |
|
32
|
-
| `*_gt_any` | Greater than any | |
|
33
|
-
| `*_gteq_any` | Greater than or equal to any | |
|
34
|
-
| `*_lt_all` | Less than all | SQL: `col < value1 AND col < value2` |
|
35
|
-
| `*_lteq_all` | Less than or equal to all | |
|
36
|
-
| `*_gt_all` | Greater than all | |
|
37
|
-
| `*_gteq_all` | Greater than or equal to all | |
|
38
|
-
| `*_not_eq_all` | none of values in a set | |
|
39
|
-
| `*_start` | Starts with | SQL: `col LIKE 'value%'` |
|
40
|
-
| `*_not_start` | Does not start with | |
|
41
|
-
| `*_start_any` | Starts with any of | |
|
42
|
-
| `*_start_all` | Starts with all of | |
|
43
|
-
| `*_not_start_any` | Does not start with any of | |
|
44
|
-
| `*_not_start_all` | Does not start with all of | |
|
45
|
-
| `*_end` | Ends with | SQL: `col LIKE '%value'` |
|
46
|
-
| `*_not_end` | Does not end with | |
|
47
|
-
| `*_end_any` | Ends with any of | |
|
48
|
-
| `*_end_all` | Ends with all of | |
|
49
|
-
| `*_not_end_any` | | |
|
50
|
-
| `*_not_end_all` | | |
|
51
|
-
| `*_cont` | Contains value | uses `LIKE` |
|
52
|
-
| `*_cont_any` | Contains any of | |
|
53
|
-
| `*_cont_all` | Contains all of | |
|
54
|
-
| `*_not_cont` | Does not contain |
|
55
|
-
| `*_not_cont_any` | Does not contain any of | |
|
56
|
-
| `*_not_cont_all` | Does not contain all of | |
|
57
|
-
| `*_i_cont` | Contains value with case insensitive | uses `ILIKE` |
|
58
|
-
| `*_i_cont_any` | Contains any of values with case insensitive | |
|
59
|
-
| `*_i_cont_all` | Contains all of values with case insensitive | |
|
60
|
-
| `*_not_i_cont` | Does not contain with case insensitive |
|
61
|
-
| `*_not_i_cont_any` | Does not contain any of values with case insensitive | |
|
62
|
-
| `*_not_i_cont_all` | Does not contain all of values with case insensitive | |
|
63
|
-
| `*_true` | is true | |
|
64
|
-
| `*_false` | is false | |
|
65
|
-
|
66
|
-
|
67
|
-
See full list: https://github.com/activerecord-hackery/ransack/blob/main/lib/ransack/locale/en.yml#L16
|