Posted almost 7 years ago. Visible to the public.

Returning an empty ActiveRecord scope

Returning an empty scope can come in handy, e.g. as a default object. In Rails 4 you can achieve this by calling none Archive on your ActiveRecord model.

MyModel.none # returns an empty ActiveRecord::Relation object

For older Rails versions you can use the attached initializer to get a none scope.

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Andreas Robecke
Last edit:
almost 7 years ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Andreas Robecke to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more