All threads / How do I do multiparameter filter

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I do multiparameter filter

Jaroslav Horák asked in Rails

Hi,
I have some sort of e-shop. I have Category model and Product model. Product has some parameters like color, material, price etc.
My question is what approach to use to filter by these parameters and categories.
Best way to include url too to be SEO friendly. Example:
www.example.com/category/subcategory/color/material?priceFrom=100&priceTo=1000
Is there some gem? Or what do you use?

Not sure how you'd get this into a URL, but a very common gem I see for operations like this is ransack:

https://github.com/activerecord-hackery/ransack

It generates a SQL query based on whatever the user puts in. It's very fast, but the one drawback is it only works with your database columns.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.