Hello,
I have a situation with the multiform search and I want to implement the solution with the usage of select boxes and checkboxes. For a better representation - I have these search fields (for autocommerce website):
Mark (selectbox1) // Model (selectbox2)
Price from (selectbox3) // Price to (selectbox5)
In ruby (on rails) I'm doing something like this:
@vehicles = Vehicle.search where: {
mark: params[:mark],
model: params[:model]
price: params[price_from]..params[:price_to]
}
Question: Supposedly user just selects _price range_ - how do I still query all other fields with the "select all" query? But other times user will select just the mark and the model and I want to query all prices.. What is the select all operator for a specific field where rules for other fields still apply?
So.. how do I do something like this:
@vehicles = Vehicle.search where: {
mark: params[:mark].blank? ? params[mark] : select_all_from_mark
model: params[:model].blank? ? params[:model] : select_all_from_mark
price: params[price_from]..params[:price_to]
}
Thanks, couldn't make it work.
One way is:
where = {price: params[price_from]..params[:price_to]}
where[:mark] = params[:mark] if params[:mark]
where[:model] = params[:model] if params[:model]
@vehicles = Vehicle.search where: where
Ankane thanks for the reply.
This doesn't seem to work.
Must be something else with your set up. I use this pattern frequently.
I get a Syntax error with this:
where = {price: params[:price_from]..params[:price_to]}
where[:mark] = params[:mark] if params[:mark]
where[:model] = params[:model] if params[:model]
@vehicles = Vehicle.search where: where
bump
Cleaning up issues
Most helpful comment
One way is: