Filter objects or user-driven query building
If we continue our web development simplification that we started at the beginning of this chapter, we can say that besides forms and links, we build data tables and lists. For example, a list of repositories on GitHub or an inbox in a web email client. What do these interfaces have in common? They all have filtering, sorting, and search controls available to users. Whenever we display a large amount of homogeneous data to a user, we want to make their life easier and allow narrowing down the scope.
Such user-driven querying requires processing input parameters and applying transformations to the base dataset based on the values provided. Let’s see how we can implement this in a Ruby on Rails application.
Filtering in controllers
Just like before, we start with a pure Rails way of solving this problem. For parameter-based filtering, that means putting transformation logic right into the controller class.
Let’s consider...