But I had trouble setting the default sort order for the results if not filtering had taken place or if no column header had been clicked. What I found on the web was a little confusing. Here's how it works (as of Feb 2010).
The model has a list of companies and I want the default search order to use their names.
In your controller:
@search = Company.search(params[:search])
@search.order ||= :ascend_by_name
@companies = @search.all.paginate :page => params[:page], :per_page => 20
Note that you set the order in @search and leave out the :order parameter to paginate.
Simple, elegant, love it...
2 comments:
Thank you for that tip it help me a lot :)
Paul
Thanks! Saved me some time! :)
Post a Comment