【发布时间】:2014-08-06 15:00:05
【问题描述】:
这是一个装饰器
app/decorators/campaign_decorator.rb
class CampaignDecorator < Draper::Decorator
delegate_all Campaign::Campaign
def created_at
helpers.content_tag :span, class: 'time' do
object.created_at.strftime("%a %m/%d/%y")
end
end
def custom_method
'hello there!'
end
end
当我调用CampaignDecorator.custom_method 时,它找不到方法。同样CampaignDecorator.first.created_at 返回未格式化的日期。
谁能告诉我我错过了什么?
【问题讨论】:
-
我不知道 Draper,但可以肯定的是,您的
custom_method被定义为实例方法,但您在类级别调用它(没有任何 CampaignDecorator 实例)。
标签: ruby-on-rails ruby-on-rails-3 activerecord draper