Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Last active December 16, 2015 16:19
Show Gist options
  • Save thejefflarson/5462303 to your computer and use it in GitHub Desktop.
Save thejefflarson/5462303 to your computer and use it in GitHub Desktop.
# you're fucking kidding me with this shit rails
def sort_string(sort, by)
sort = Model.column_names.include?(sort) ? sort : 'field'
by = ['asc', 'desc'].include?(by) ? by : 'desc'
"#{sort} #{by}"
end
# use: Model.order(sort_string sort, by)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment