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?
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:
Add
app/decorators
to the Rails autoload path:in
config/application.rb
:then, the decorator classes under that path should automatically be loaded, even in the
rails console
. Example: