diff options
Diffstat (limited to 'config/initializers/ransack.rb')
| -rw-r--r-- | config/initializers/ransack.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/config/initializers/ransack.rb b/config/initializers/ransack.rb index 659ee4a79..09d895e47 100644 --- a/config/initializers/ransack.rb +++ b/config/initializers/ransack.rb @@ -4,6 +4,7 @@ Ransack.configure do |config| formatter: proc { |v| v.split(' to ') }, type: :string end + module Arel module Predications def between other @@ -11,3 +12,19 @@ module Arel end end end + +module Ransack + module Constants + module_function + # replace % \ to \% \\ + def escape_wildcards(unescaped) + case ActiveRecord::Base.connection.adapter_name + when "Mysql2".freeze, "PostgreSQL".freeze, "PostGIS".freeze + # Necessary for PostgreSQL and MySQL + unescaped.to_s.gsub(/([\\|\%|_|.])/, '\\\\\\1') + else + unescaped + end + end + end +end |
