activerecord-hackery/ransack — pull request #438 by caleb (2014-10-02 04:59:49+00:00)
Title: Add multiple sort field support in sort_link

Let me know what you think of this patch. I would love to see this included in ransack, since this is a problem I run into frequently.

This patch allows users to sort on multiple fields with the sort_link
helper.

To specify sorting on multiple fields:

``ruby
sort_link(:kind, [:kind, 'name asc'])
``

This will create a sort link that sorts first by kind, and then by
name. The first `:kind` parameter ensures that the link generated
shows the sort status of the `kind` field.

When you specify a sort direction in the sort fields array, the
direction is locked to that direction. In the above example, clicking
the resulting link would toggle sorting of the kind field, but the name
field would always sort ascending.

Also added was the ability to specify multiple default_order fields
with a hash:

``ruby
sort_link(:kind, [:kind, :name],
:default_order => { :name => 'asc', :kind => 'desc' })
``

Clicking the resulting link will toggle the sort directions of both
`name` and `kind`, sorting the `name` field by default ascending, and
the `kind` field descending.

If you wanted to specify a label, you would add it after the array or sort fields:

``ruby
sort_link(:kind, [:kind, :name], "Property Kind",
:default_order => 'asc')
``