Skip to content

Commit 39cc369

Browse files
authored
Merge pull request #33 from blocknotes/refactor/make-ransack-distinct-optional
refactor: make Ransack distinct optional
2 parents b42317e + b0e2b55 commit 39cc369

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/administrate_ransack/searchable.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
module AdministrateRansack
66
module Searchable
77
def scoped_resource
8-
options = respond_to?(:ransack_options) ? ransack_options : {}
8+
options = respond_to?(:ransack_options, true) ? ransack_options : {}
9+
distinct = respond_to?(:ransack_result_distinct, true) ? ransack_result_distinct : true
910
@ransack_results = super.ransack(params[:q], **options)
10-
@ransack_results.result(distinct: true)
11+
@ransack_results.result(distinct: distinct)
1112
end
1213

1314
# ref => https://github.com/thoughtbot/administrate/blob/v0.18.0/app/helpers/administrate/application_helper.rb#L72-L78

spec/dummy/app/controllers/admin/posts_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ def ransack_options
66
{ ignore_unknown_conditions: false }
77
end
88

9+
def ransack_result_distinct
10+
false
11+
end
12+
913
# Overwrite any of the RESTful controller actions to implement custom behavior
1014
# For example, you may want to send an email after a foo is updated.
1115
#

0 commit comments

Comments
 (0)