Scope of Office Manager

Ryan Locascio
2 min readMay 25, 2021

In my Rails project Office Manager, I used a scope method to provide a search bar. The search bar allows the user to search by state. This provides the companies that reside in that state.

Scoping allows you to specify commonly-used queries which can be referenced as method calls on the association objects or models. I created a scope method in my models/office class, I created this scope method so it would be chain-able.

I then added a search action in my office controller:

This search action gives the user the route to the search bar. Setting the parameters that if the search is blank it will render a blank output. If a parameter such as a state name is placed in the search bar the view in views/offices/search will handle the logic of what the user will see:

Creating a search method allows us to chain the method to refine the search.

--

--