Draper adds decorator objects around Rails models so presentation helpers and formatted attributes live in testable view-model classes instead of helpers or models.
Overview
Draper is a Ruby gem that introduces decorator classes wrapping ActiveRecord models in Rails apps. Controllers call decorate on models before rendering, and views call methods on the decorator as if it were the model.
Decorators inherit from Draper::Decorator, live under app/decorators, and typically use delegate_all to expose underlying model methods while adding presentation-specific methods such as formatted dates or HTML links.
The gem supports decorating single records, collections, associated records, and finder results via decorates_finders. CollectionDecorator can add pagination helpers compatible with Kaminari or will_paginate.
Generators can scaffold ApplicationDecorator, per-model decorators, or hook controller generators. Helpers remain available through the h proxy inside decorators. Current releases target Rails 5.2 and Ruby 2.4 or newer per project notes.
Key features
- Decorator classes per Rails model
- delegate_all to underlying records
- Collection and association decoration
- Finder methods returning decorators
- Helper access via h proxy
- Rails generators for decorators
Use cases
- Moving view formatting out of helpers
- Keeping fat presentation off models
- Testing display logic in isolation