Scopes are used to assign complex ActiveRecord queries into customized methods using Ruby on Rails.

Inside your models, you can define a scope as a new method that returns a lambda function for calling queries you’re probably used to using inside your controllers.

A use case for scopes is often for filtering by status, date, date ranges, ordering, groupings, and more. ActiveRecord already makes it quite easy to return rich data from your database. Combining those superpowers with scopes allow you to define more memorable queries that you and your team can harness through your Ruby on Rails application.

Read the full blog post here:
https://web-crunch.com/posts/how-to-use-scopes-ruby-on-rails

#ruby-on-rails #developer #programming

How to use Scopes in Ruby on Rails
2.15 GEEK