Method: Brainstem::Presenter#calculate_sort_name_and_direction
- Defined in:
- lib/brainstem/presenter.rb
#calculate_sort_name_and_direction(user_params = {}) ⇒ Object
Clean and validate a sort order and direction from user params.
250 251 252 253 254 255 256 257 258 259 |
# File 'lib/brainstem/presenter.rb', line 250 def calculate_sort_name_and_direction(user_params = {}) default_column, default_direction = (configuration[:default_sort_order] || "updated_at:desc").split(":") sort_name, direction = user_params['order'].to_s.split(":") unless sort_name.present? && configuration[:sort_orders][sort_name] sort_name = default_column direction = default_direction end [sort_name, direction == 'desc' ? 'desc' : 'asc'] end |