Rails scopes might just return all resources
ActiveRecord's scopes are meant to be composable and intended to only ever return an ActiveRecord relation.
If you make a mistake with your scope and have it return something like a nil
or false
, Rails will return all records for that class in order to maintain composability.
If you are intentionally writing something that might return an empty value, use a class method rather than adding a scope in order to prevent bugs
Tweet