Intridea Blog: Technology, Design, Business

Back to Blog

Get in Touch

You're currently viewing posts tagged with: "default_scope"

Black Magic Rails: default_scope

By Intridea | September 26, 2011 rails, best practices, debate, default_scope
Medium

In a community where best practices are always being redefined, black magic practices aren't hard to come by. For our first discussion on controversial Rails practices we're focusing on default_scope.

Default Scopes, (Briefly) Explained

A default scope is a Rails method provided by ActiveRecord which allows you to specify conditions for all the finders associated with a particular model. It is commonly used to specify ordering directly in your ActiveRecord model.

Sounds like a fairly good tool, but don't be fooled. Popular opinion dictates that default_scope is at the very least a chaotic good tool, bordering cunningly on the edge of the black magic stratosphere.

Read more…