class Object

Public Instance Methods

format_predicate(attribute) click to toggle source

Original method doesn't respect the arity of expressions See: lib/ransack/adapters/active_record/ransack/nodes/condition.rb#L30-L42

# File lib/jsonapi/patches.rb, line 65
def format_predicate(attribute)
  original_format_predicate(attribute)
rescue ArgumentError
  arel_pred = arel_predicate_for_attribute(attribute)
  attribute.attr.public_send(arel_pred)
end
visit_Ransack_Nodes_Sort(node) click to toggle source

Original method assumes sorting is done only by attributes

# File lib/jsonapi/patches.rb, line 41
def visit_Ransack_Nodes_Sort(node)
  # Try the default sorting visitor method...
  binded = original_visit_Ransack_Nodes_Sort(node)
  valid = (binded.valid? if binded.respond_to?(:valid?)) || true
  return binded if binded.present? && valid

  # Fallback to support the expressions...
  binded = Ransack::Nodes::Condition.extract(node.context, node.name, nil)
  valid = (binded.valid? if binded.respond_to?(:valid?)) || true
  return unless binded.present? && valid

  arel_pred = binded.arel_predicate
  # Remove any alias when sorting...
  arel_pred.alias = nil if arel_pred.respond_to?(:alias=)
  arel_pred.public_send(node.dir)
end