Module: SortItOut::Sortable::InstanceMethods

Defined in:
lib/sort_it_out/sortable.rb

Instance Method Summary collapse

Instance Method Details

#resolve_sortObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sort_it_out/sortable.rb', line 25

def resolve_sort
  order = params[:order]
  unless order
    if self.options[:default].is_a?( String ) || self.options[:default].is_a?( Symbol )
      order = params[:order] = self.options[:default]
    elsif self.options[:default].is_a?( Hash )
      order = params[:order] = self.options[:default][:attribute]
      params[:direction] = self.options[:default][:direction]
    end
  end

  params[:direction] = 'ASC' unless params[:direction]
  @order = order.nil? ? "" : resolve_order_clause( order, params[:direction] )
end