Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Strategies: Draper (Decorator) implementation

listrophy edited this page · 3 revisions

If you want to use the Draper gem together with Decent Exposure, you can use the following strategy:

class DecoratorStrategy < DecentExposure::ActiveRecordWithEagerAttributesStrategy

  def resource
    r = super.tap { |r| r.class.send(:include, Draper::Decoratable) unless r.respond_to?(:decorate) }
    r.decorate
  end
end
class UsersController < ApplicationController
  expose :user, strategy: DecoratorStrategy
end

It uses the default strategy (ActiveRecordWithEagerAttributesStrategy) and does two things on top of it:

  1. Dynamically include Draper::Decoratable to the exposed object;
  2. call .decorate on the resource being exposed by decent exposure.
Something went wrong with that request. Please try again.