#77 ✓resolved

It would be nice to have default order_by and conditions

Reported by Vidmantas | March 30th, 2009 @ 06:43 AM


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

    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.

  • Vidmantas

    Vidmantas March 30th, 2009 @ 12:36 PM

    Well, in my case default_scope won't work, because in current situation that "default condition" depends on the user logged in. I mean conditions, ordering should be working - I'll check that

  • Vidmantas

    Vidmantas March 31st, 2009 @ 11:41 AM

    I've tried default_scope with both - :order and :conditions - options and searchlogic works nice as expected.

    Still, default_scope doesn't solve dynamic "defaults". It would be very nice feature while it's not needed by many programmers I believe :-)

  • aferra (at gmail)

    aferra (at gmail) June 21st, 2009 @ 07:58 AM


    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]) end


  • aferra (at gmail)

    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])

    Dear Entp, 'preview' would be nice. :)

  • Vidmantas

    Vidmantas June 21st, 2009 @ 11:44 AM

    aferra, many thanks! Never heard about that method (reverse_merge), but now it's clear. Thanks!

  • Ben Johnson

    Ben Johnson June 24th, 2009 @ 02:12 AM

    • State changed from “open” to “resolved”

    Let me know if you still have problems.

  • seomaster

    seomaster April 11th, 2021 @ 04:30 AM

    This is very appealing, however , it is very important that will mouse click on the connection: check this site

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.

New-ticket Create new ticket

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.

People watching this ticket