
It would be nice to have default order_by and conditions
Reported by Vidmantas | March 30th, 2009 @ 06:43 AM
Hi,
it would be really nice to have some kind of 'default' conditions and order_by options. For example I want to show somehow filtered and sorted entries by default unless they are overwritten with the incomming search.
Or maybe it's implemented and I just can't find it? :-)
Comments and changes to this ticket
-
Ben Johnson March 30th, 2009 @ 11:45 AM
- State changed from new to open
I think the best solution for this is default_scope. It's a new feature and I'm not sure if it works with search logic or not.
-
aferra (at gmail) June 21st, 2009 @ 07:58 AM
@Vidmantas
Ruby to the rescue!
There's a lot of ways you could do this but, this is concise an works well:
def index
search_options = (params[:search] || {}).reverse_merge(:order => 'ascend_by_username') @search = User.search(search_options) @users = @search.paginate(:page => params[:page]) endBest,
Andy -
aferra (at gmail) June 21st, 2009 @ 08:00 AM
Jezz scuse the horrendous formatting.
def index search_options = (params[:search] || {}).reverse_merge(:order => 'ascend_by_username') @search = User.search(search_options) @users = @search.paginate(:page => params[:page]) end
Dear Entp, 'preview' would be nice. :)
-
Ben Johnson June 24th, 2009 @ 02:12 AM
- State changed from open to resolved
Let me know if you still have problems.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Provides common named scopes and object based searching.