This came across my path this week: Joël Quenneville’s article, Decorating ActiveRecord, which outlines some hazards when you go about decorating ActiveRecord models.

Do read the article, it’s good.


Here’s the tl;dr for my memory:

If you’re decorating an ActiveRecord or ActiveModel object in Rails, you probably want to define the following to ensure the decorator works the way you expect instead of silently delegating to the underlying object:

1
2
3
4
5
6
7
class Profile < SimpleDelegator
  extend ActiveModel::Naming

  def to_model
    self
  end
end

Source