Search code examples
ruby-on-railsruby-on-rails-3decoratordraper

How to include Draper Decorators in Rails Console?


I'd like to see the output of some of my Draper Decorators in Rails console (https://github.com/drapergem/draper and http://railscasts.com/episodes/286-draper). To do so, I was looking for a way to include a decorator and its methods similar to as we would an application helper:

 include ActionView::ApplicationHelper

A draper decorator inherits from an ApplicationDecorator, which inherits from Draper::Base

 class ApplicationDecorator < Draper::Base
 end

 class MaterialDecorator < ApplicationDecorator
    decorates :material
    #methods to decorate your material..
 end

I've tried include Draper::Base::MaterialDecorator, include ApplicationDecorator::MaterialDecorator, and some other similar variations with no luck.

How can I include a decorator such as the Material Decorator above in rails console?


Solution

  • So, it turns out (unless someone can show otherwise) that this isn't the way you test draper decorator output in rails console..

    Instead, you just do:

     material = Material.first
     material = MaterialDecorator.decorate(material)
     material.some_decorator_method