Introduction
Scopes help you write reusable and clear database queries in Rails models. They keep your code clean and easy to understand.
When you want to reuse a common database filter in many places.
When you want to give a name to a specific query for better readability.
When you want to chain multiple queries together easily.
When you want to keep your controller or view code simple by moving query logic to the model.