I want to implement a decoration pattern such that a Rails object has presentation-related methods encapsulated in one place.
Given a model named Article
and a presentation method named to_json
- Create an
ArticleDecorator
module in /app/decorators/ - Automatically include that module into the matching model at load time
- Use the methods like
Article.find(1).to_json
orArticle.find(1).formatted_title
- Pros: Transparency