Only show results that match all search criteria with Ransack gem

Viewed 227

I have a Rails app that searches tasks. A task has field called "Tools" that lists all the tools, if any, that are required to complete this task.

For a basic example, the task "Paint the office" might have tools "paintbrush" and "paint bucket."

When I search, I indicate what tools I have on hand. I ONLY want to see "Paint the office" in search results if I checked both "paintbrush" and "paint bucket." In other words, if I only have a paintbrush with no bucket, I don't want to see the task, because I can't complete it now.

However, when I'm searching, I'm indicating all the tools I have. I might pick "paintbrush" "paint bucket" and also "computer" and "phone." This means that a matches_all query doesn't bring up "Paint the office" if I check additional tools.

I'm hoping I'm just looking at this the wrong way and someone will be able to point me to a predicate that works. I might also have outgrown ransack, but this is a personal hobby project so I'd love to keep it mostly as-is.

Thank you very much.

0 Answers
Related