Just thought I would do a short write up on a technique we use at work that we call “buckets.” I’m sure many people do something similar, but it is an extremely helpful technique. Buckets allow you to easily narrow down your search query based on a variable number of inputs. All the code in this article is for Rails 2.x.x but should translate to Rails 3 with little problems.
Consider this model
The bucket pattern allows you to stack an infinite number of named_scopes on top of each other to limit the “scope” of what you’re searching for. Consider that we wanted to find people based on the input of a form.