Skip to content

Instantly share code, notes, and snippets.

@StaverDmitry
Last active April 21, 2017 18:26
Show Gist options
  • Save StaverDmitry/c8c71f69d5f136b75b6bb296e13bdefe to your computer and use it in GitHub Desktop.
Save StaverDmitry/c8c71f69d5f136b75b6bb296e13bdefe to your computer and use it in GitHub Desktop.
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