App001 a/d sorting for 7 columns in view selector

Thought this might be a bit tricky, but not too bad.
Could be dried up more, but that's not unusual.

    @percentage_sort_direction  = 'A' # default, stops errors and also works for the 'else' of the if's
    @year_sort_direction        = 'A' 
    ...etc.
    if (params[:sort_column]) == "percentage"
      if (params[:sort_percentage_asc_or_desc]) # prevents error.
        if (params[:sort_percentage_asc_or_desc]).upcase == 'A'
          { @the_sort = 'percentage ASC', @percentage_sort_direction = 'D' }
        else
          @the_sort = 'percentage DESC'
        end
        @the_sort = @the_sort + ', year DESC, statistics_month_id ASC, browser_version_id DESC, operating_system_id DESC, resolution_id DESC, color_depth_id DESC'
      end
    elsif (params[:sort_column]) == 'by_year' 
    ...etc.

plus in view:
<%= link_to '%', :sort_percentage_asc_or_desc => @percentage_sort_direction, :sort_column => 'percentage', :resolution => params[:resolution], :color => params[:color], :browser => params[:browser], :os_source => params[:os_source] %>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s