#74 ✓resolved
Tee Parham

Ignore certain select items in conditions

Reported by Tee Parham | March 27th, 2009 @ 05:55 PM

I want to ignore a certain value from a select list in my conditions. How do I specify that?

Here's an example where I have a select list of 'Any', 'Joe', and 'Bob'. If 'Any' is selected, I want to exclude that condition and thus find all users. Is there a better way than manually checking for the 'Any' value and then deleting that condition in the controller? If not, what is the preferred way to remove a condition?


  # app/views/users/index.html.haml
  - form_for @search do |f|
    - f.fields_for @search.conditions do |users|
      = users.select :first_name, ['Any','Joe','Bob']
    = f.submit "Search"

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson March 30th, 2009 @ 11:49 AM

    • State changed from “new” to “resolved”

    yes:

    user.select :first_name ["Joe", "Bob"], :include_blank => "Any"
    
  • Tee Parham

    Tee Parham March 30th, 2009 @ 04:38 PM

    • Assigned user cleared.

    Thanks for the help, Ben. It's good to know searchlogic supports the standard rails way of handling blanks (:include_blank) - duh!

    Tip for others using select lists: use collection_select if you're mapping a model collection to the select list:

    Scope collection_select for the form you're in:

    user.collection_select :user_id, User.find(:all), :id, :name, {include_blank=>"Any"}, {:class=>"fancy"}
    

    http://api.rubyonrails.org/class...

    See the bottom of this topic too: http://railsforum.com/viewtopic....

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

Pages