From 67942cf853ee25cb466fb7c529cbcdd01e8b439b Mon Sep 17 00:00:00 2001 From: Marc Anguera Insa Date: Mon, 13 Aug 2018 22:20:35 +0200 Subject: [PATCH] Re-implement the member_uid searcher by avoiding the column casting thing (gives some problems when sorting the "casted" column as an string). The new strategy: combine both fields in the controller by manupilating the query parameters sent to Ransack. --- app/controllers/users_controller.rb | 9 ++++++++- app/models/member.rb | 5 ----- app/views/users/index.html.erb | 2 +- spec/controllers/users_controller_spec.rb | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9f1dd87a6..dd413abdb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -60,7 +60,14 @@ def update private def search_params - {s: 'member_uid asc'}.merge(params.fetch(:q, {})) + q = params.fetch(:q, {}) + + if params[:q].present? + q[:member_uid_eq] = q[:user_username_or_user_email_contains] + q[:m] = 'or' + end + + { s: 'member_uid asc' }.merge(q) end def scoped_users diff --git a/app/models/member.rb b/app/models/member.rb index d84d55e5d..6c0b9aeca 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,9 +1,4 @@ class Member < ActiveRecord::Base - # Cast the member_uid integer to a string to allow pg ILIKE search (from Ransack *_contains) - ransacker :member_uid do - Arel.sql("to_char(member_uid, '9999999')") - end - belongs_to :user belongs_to :organization has_one :account, as: :accountable diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 126e72e87..5ee524add 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -11,7 +11,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :user_username_or_user_email_or_member_uid_contains, class: "form-control" %> + <%= f.search_field :user_username_or_user_email_contains, class: "form-control" %>