Skip to content

Instantly share code, notes, and snippets.

View cyb-ahmadh's full-sized avatar

Ahmad hamza cyb-ahmadh

  • Cybage Software
  • Pune
View GitHub Profile
@dmexs
dmexs / example_controller.rb
Last active April 9, 2018 00:43 — forked from TheKidCoder/example_controller.rb
Rails - Sanitize Ordering Params
class ClientsController
include OrderingHelpers
def index
# order_by sanitation should work fine here, with sanitation to created_by if invalid
@clients = Clients.order(sanitized_ordering).where(user_id: current_user.id)
# trying to order_by sales.date for example will fail here even if it's valid if the current controller is not ClientController
@clients = Clients.joins(:sales).order(sanitized_ordering.where(user_id: current_user.id)
@justinweiss
justinweiss / filterable.rb
Last active January 11, 2024 07:28
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call