문제

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')
도움이 되었습니까?

해결책

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 %>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top