Gibson
Gibson

Reputation: 2085

How to pass multiple params in a query?

Im making some filters, and I have a form that searches with multiple params.

I want to search products by :category and :price at the same time, how can I make the query?

Im trying:

@pins = Pin.where('category CONTAINS ?', params[:category] && 'min_price BETWEEN ? AND ?', params[:pin][:min_value], params[:pin][:max_value])

But It won't work!

Upvotes: 0

Views: 544

Answers (1)

Mori
Mori

Reputation: 27789

@pins = Pin.where('category LIKE ? and min_price BETWEEN ? AND ?',
                  params[:category], params[:pin][:min_value], 
                  params[:pin][:max_value])

Upvotes: 2

Related Questions