class Task < ActiveRecord::Base
attr_accessible :due_date, :text
def self.this_week
where(:due_date => Date.today.beginning_of_week..Date.today.end_of_week)
end
end
class Important < ActiveRecord::Base
attr_accessible :email
has_one :task, :as => :taskable, :dependent => :destroy
delegate this_week, :to => :task
end
到目前为止,当我尝试Important.this_week
. 我收到一条错误消息,说没有this_week
为类定义方法...
有任何想法吗?我什至可以委托给这样的类方法吗?我可能有一两个Task
以这种方式扩展的类,所以我很好奇它是如何以一种不会将一堆代码复制到每个实现类的方式工作的。