Skip to content

Instantly share code, notes, and snippets.

@ilyakatz
Created August 12, 2014 17:35
Show Gist options
  • Save ilyakatz/ad94969b400c311f2522 to your computer and use it in GitHub Desktop.
Save ilyakatz/ad94969b400c311f2522 to your computer and use it in GitHub Desktop.
Custom default order order in active_admin
# initializers/active_admin.rb
module ActiveAdmin
class OrderClause
alias_method :initialize_old, :initialize
alias_method :valid_old?, :valid?
alias_method :to_sql_old, :to_sql
def initialize(clause)
if clause.class == String
initialize_old(clause)
else
@clause = clause[:sql]
end
end
def valid?
if @clause
@clause.present?
else
valid_old?
end
end
def to_sql(active_admin_config)
if @clause
@clause
else
to_sql_old(active_admin_config)
end
end
end
end
# admin/product.rb
ActiveAdmin.register Product do
config.sort_order = { sql: "shipments.shipment_date ASC, products.name ASC" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment