Created
August 12, 2014 17:35
-
-
Save ilyakatz/ad94969b400c311f2522 to your computer and use it in GitHub Desktop.
Custom default order order in active_admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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