Ruby on Rails Explained
scope
Oct 22, 2020 - Daniel Viklund
Scoping in Ruby on Rails allows us to define frequently used queries which can be invoked as method calls on either association objects, relations or models. You can reference the standard query methods like where
, joins
and includes
. The requirements of defined scopes is that it must return either an instance of ActiveRecord::Relation
or nil
. This allows us to chain multiple scopes together for highly flexible query construction.