Add missing partial and wildcard search on /admin/blocked_domains

This commit is contained in:
Thiago Youssef 2022-03-29 11:18:46 +03:00
parent eaf89a02f7
commit 4f96441f26
2 changed files with 6 additions and 10 deletions

View file

@ -5,7 +5,7 @@ module Admin
def index
params[:q] ||= {}
domains = BlockedDomain.all.order(:name)
@q = domains.ransack(params[:q])
@q = domains.ransack(PartialSearchFormatter.format(params[:q]))
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
@ -13,13 +13,10 @@ module Admin
end
def new
@domain = BlockedDomain.new
end
def create
@domain = BlockedDomain.new(blocked_domain_params)
if @domain.save
@ -29,18 +26,16 @@ module Admin
flash.now[:alert] = I18n.t('failed_to_add_domain')
render 'new'
end
end
def delete
if BlockedDomain.find(params[:id]).destroy
flash[:notice] = I18n.t('domain_deleted')
redirect_to admin_blocked_domains_path
else
flash.now[:alert] = I18n.t('failed_to_delete_domain')
redirect_to admin_blocked_domains_path
end
redirect_to admin_blocked_domains_path
end
def blocked_domain_params

View file

@ -1,11 +1,12 @@
class PartialSearchFormatter
def self.format(search_params)
def self.format(params)
percentage = '%'
search_params = params.deep_dup
search_params.each do |key, value|
next unless key.include?('matches') && value.present?
value.prepend(percentage).concat(percentage)
value << percentage
end
search_params