Skip to content

Instantly share code, notes, and snippets.

@iloveivyxuan
iloveivyxuan / arel.rb
Created August 15, 2017 06:49
Define Area Nodes -- Add a contain operator to Arel Nodes
# app/config/initializers/arel.rb
require 'arel/nodes/binary'
require 'arel/predications'
require 'arel/visitors/postgresql'
module Arel
class Nodes::ContainsArray < Arel::Nodes::Binary
def operator
:"@>"
@iloveivyxuan
iloveivyxuan / ransack.rb
Created August 15, 2017 06:56
An example of how to add a contain predicate to Arel
# app/config/initializers/ransack.rb
Ransack.configure do |config|
config.add_predicate 'contains',
arel_predicate: 'contains',
formatter: proc { |v| "{#{v}}" },
validator: proc { |v| v.present? },
type: :string
end