Quantcast
Viewing all articles
Browse latest Browse all 9

Extending Your Models in Rails 3 with App Concerns

App Concerns are awesome.

They've been used for years by 37signals, but there's built-in support for them in Rails 3. They're basically a really easy way to DRY up your code, by letting you easily extend your models with a few handy extras like smart loading. Most Rails 3 gems (like Mongoid v2.0, for instance) use App Concerns to organize their code. Not only is this design pattern great for reusing code across models, but I also use it to refactor large models into component pieces for better readability.

Here's a basic example I was showing to a friend who is a new programmer (pardon some of the obvious OOP notes):

Permalink | Leave a comment  »


Viewing all articles
Browse latest Browse all 9

Trending Articles