please explain me difference between scope and class methods.
Thank you
please explain me difference between scope and class methods.
Thank you
Scope method takes a block, methods takes input (I’m not very experienced, I’m just learning too).
From the guides for Rails 6:
A scope will always return an
ActiveRecord::Relation
object, even if the conditional evaluates tofalse
, whereas a class method, will returnnil
. This can causeNoMethodError
when chaining class methods with conditionals, if any of the conditionals returnfalse
.
So scopes always return an ActiveRecord::Relation
. A class method, returns anything you want.