Last active
December 16, 2015 16:19
-
-
Save thejefflarson/5462303 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
# 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