我正在遵循Draper gem文档,但相关模型没有被装饰。下面是我的顶级装饰师的一个片段:
module Admin
class OrderDecorator < Draper::Decorator
delegate_all
decorates_finders
decorates_association :line_item
def amount
model.amount.nil? ? 0 : model.amount
end
end
end
下面是我的协会装饰师的一个片段:
module Admin
class LineItemDecorator < Draper::Decorator
delegate_all
def options
model.options.present? ? model.options.to_s : 'N/A'
end
end
end
以下是控制器中调用装饰器的方法:
def show
@subject = Admin::OrderDecorator.find(params[:id])
end
它在视图中的使用方式如下:
@subject.line_items.each do |li|
= li.options
...等
LineItemDecorator上的options方法被忽略了——如果它为nil,则不显示任何内容,而不是“不适用”。我把装订好了。撬入options方法,它就永远不会被调用。有人能看到我错过了什么吗?
提前非常感谢。