PostgreSQL SIMILAR TO を使いたかった。
config/initializers/arel_override.rb
module ArelVisitorsPostgreSQLOverride
# https://github.com/rails/rails/blob/v6.0.3.2/activerecord/lib/arel/visitors/postgresql.rb#L29
def visit_Arel_Nodes_Regexp(o, collector)
# op = o.case_sensitive ? " ~ " : " ~* "
op = " SIMILAR TO "
infix_value o, collector, op
end
end
Arel::Visitors::PostgreSQL.prepend(ArelVisitorsPostgreSQLOverride)
config/initializers/ransack.rb
Ransack.configure do |config|
config.add_predicate 'matches_regexp', arel_predicate: 'matches_regexp'
end