Question

I'm using meta-search gem for searching and ordering columns. This code will order records only in one direction:

scope_name.search('meta_sort' => 'name_and_status.desc')

How can I sort columns in different directions? E.g.

scope_name.search('meta_sort' => 'name.asc_and_status.desc')
Was it helpful?

Solution

meta_search only allow one direction of sort. You can just use order after search.

scope_name.search(params[:search]).order('name, status desc')

If you use the sort_link in the page, you can specify the order in the page. But I havn't used this.

scope_name.search('meta_sort' => 'name_and_status.desc')

<%= sort_link @search, :name, "Name", :default_order => :asc %>
<%= sort_link @search, :status, "Status", :default_order => :desc %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top