#102 ✓resolved
atmorell

Join scopes with OR

Reported by atmorell | July 20th, 2009 @ 10:12 AM

Hey Ben,

I have a form where the user can select price ranges:

Form:

  • form_for @search do |f| =f.text_field :title_like %h2 Prices =f.check_box :cheap_price =f.check_box :budget_price =f.check_box :normal_price =f.submit

Model:

Painting.named_scope :cheap_price, :conditions => {:price => 1..500}
Painting.named_scope :budget_price, :conditions => {:price => 500..1000}
Painting.named_scope :normal_price, :conditions => {:price => 1000..2000}

My problem is that the scopes is joined with AND. I would like to join with OR, so that the visitor can e.g see cheap_price and budget_price at the same time etc.

Any suggestions?

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson July 20th, 2009 @ 05:35 PM

    • State changed from “new” to “resolved”

    How would you do this in the console? Because I would create scopes that allow me to do this in the console. Once youve done that creating a form is easy. Maybe you make a named_scope that accepts an array or ranges and you do your magic in there. Then just create a form that passes an array to that scope.

  • Ben Johnson

    Ben Johnson July 20th, 2009 @ 05:37 PM

    Also, to be honest, I would probably just make a slider that allows them to filter, or let them set their less than or greater than conditions. Cheap, budget, and normal are all subjective terms and can vary depending on how the user defines them.

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