diff --git a/app/controllers/repp/v1/accounts_controller.rb b/app/controllers/repp/v1/accounts_controller.rb index 7db2a3275..0bd75a302 100644 --- a/app/controllers/repp/v1/accounts_controller.rb +++ b/app/controllers/repp/v1/accounts_controller.rb @@ -8,7 +8,7 @@ module Repp def index records = current_user.registrar.cash_account.activities - q = records.ransack(search_params) + q = records.ransack(PartialSearchFormatter.format(search_params)) q.sorts = 'created_at desc' if q.sorts.empty? activities = q.result(distinct: true) @@ -128,7 +128,7 @@ module Repp end def search_params - index_params.fetch(:q, {}) + index_params.fetch(:q, {}) || {} end def limit diff --git a/app/controllers/repp/v1/contacts_controller.rb b/app/controllers/repp/v1/contacts_controller.rb index f9c58303c..31be5e09b 100644 --- a/app/controllers/repp/v1/contacts_controller.rb +++ b/app/controllers/repp/v1/contacts_controller.rb @@ -11,7 +11,7 @@ module Repp authorize! :check, Epp::Contact records = current_user.registrar.contacts - q = records.ransack(search_params) + q = records.ransack(PartialSearchFormatter.format(search_params)) q.sorts = 'created_at desc' if q.sorts.empty? contacts = q.result(distinct: true) @@ -123,7 +123,7 @@ module Repp end def search_params - index_params.fetch(:q, {}) + index_params.fetch(:q, {}) || {} end def domain_filter_params diff --git a/app/controllers/repp/v1/domains_controller.rb b/app/controllers/repp/v1/domains_controller.rb index ba40b13e2..29b259a67 100644 --- a/app/controllers/repp/v1/domains_controller.rb +++ b/app/controllers/repp/v1/domains_controller.rb @@ -13,7 +13,7 @@ module Repp def index authorize! :info, Epp::Domain records = current_user.registrar.domains - q = records.ransack(search_params) + q = records.ransack(PartialSearchFormatter.format(search_params)) q.sorts = ['valid_to asc', 'created_at desc'] if q.sorts.empty? # use distinct: false here due to ransack bug: # https://github.com/activerecord-hackery/ransack/issues/429 @@ -244,7 +244,7 @@ module Repp end def search_params - index_params.fetch(:q, {}) + index_params.fetch(:q, {}) || {} end def update_params diff --git a/app/controllers/repp/v1/invoices_controller.rb b/app/controllers/repp/v1/invoices_controller.rb index 1c14df329..204aba096 100644 --- a/app/controllers/repp/v1/invoices_controller.rb +++ b/app/controllers/repp/v1/invoices_controller.rb @@ -9,7 +9,7 @@ module Repp desc 'Get all invoices' def index records = current_user.registrar.invoices - q = records.ransack(search_params) + q = records.ransack(PartialSearchFormatter.format(search_params)) q.sorts = 'created_at desc' if q.sorts.empty? invoices = q.result(distinct: true) @@ -101,7 +101,7 @@ module Repp end def search_params - index_params.fetch(:q, {}) + index_params.fetch(:q, {}) || {} end def invoice_params diff --git a/app/services/partial_search_formatter.rb b/app/services/partial_search_formatter.rb index af0c7978d..268cd75fb 100644 --- a/app/services/partial_search_formatter.rb +++ b/app/services/partial_search_formatter.rb @@ -5,7 +5,7 @@ class PartialSearchFormatter search_params.each do |key, value| next unless key.include?('matches') && value.present? - value << '%' + search_params[key] = "%#{value}%" end search_params