Read more

Returning an empty ActiveRecord scope

Avatar
Andreas Robecke
October 24, 2014Software engineer

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
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more

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

Posted by Andreas Robecke to makandra dev (2014-10-24 13:40)