AR :- What is the difference between scope and class methods?

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 to false , whereas a class method, will return nil . This can cause NoMethodError when chaining class methods with conditionals, if any of the conditionals return false .

So scopes always return an ActiveRecord::Relation. A class method, returns anything you want.

4 Likes