Read more

Returning an empty ActiveRecord scope

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 Show archive.org snapshot on your ActiveRecord model.

    MyModel.none # returns an empty ActiveRecord::Relation object
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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)