Last active
April 21, 2017 18:26
-
-
Save StaverDmitry/c8c71f69d5f136b75b6bb296e13bdefe to your computer and use it in GitHub Desktop.
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
module Sortable | |
def sortable(columns=nil) | |
@@sortable ||= columns.with_indifferent_access | |
end | |
def order_condition(column='id', direction='desc') | |
direction = %w[asc desc].include?(direction) ? direction : 'desc' | |
if sortable.keys.include?(column) | |
column = sortable[column] | |
else | |
column = column_names.include?(column) ? column : 'id' | |
end | |
"#{column} #{direction}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment