问题描述
我想在Rails控制台(https://github.com/drapergem/draper和 http://railscasts.com/episodes/286-draper ).为此,我一直在寻找一种包含装饰器及其方法的方法,就像我们将应用程序助手作为它的方法一样:
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
窗帘装饰器继承自ApplicationDecorator,而ApplicationDecorator继承自Draper :: Base
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
我尝试了include Draper::Base::MaterialDecorator
,include ApplicationDecorator::MaterialDecorator
和其他一些类似的变体,但是没有运气.
I've tried include Draper::Base::MaterialDecorator
, include ApplicationDecorator::MaterialDecorator
, and some other similar variations with no luck.
如何在Rails控制台中包含一个装饰器(例如上面的Material Decorator)?
How can I include a decorator such as the Material Decorator above in rails console?
推荐答案
因此,事实证明(除非有人可以显示否则),这不是在Rails控制台中测试draper装饰器输出的方式.
So, it turns out (unless someone can show otherwise) that this isn't the way you test draper decorator output in rails console..
相反,您只是这样做:
material = Material.first
material = MaterialDecorator.decorate(material)
material.some_decorator_method
这篇关于如何在Rails控制台中包含Draper装饰器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!