好吧,事实证明这是行不通的:
class StudentActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc").decorate
end
end
我猜这是因为命名空间查询PublicActivity::Activty
不是从 ActiveRecord 继承的,因此不包括Draper::Decoratable
,但我不确定。如果我错了,请纠正我。
但是,使用 Draper,您可以装饰对象以及查询,所以这确实有效......
class StudentActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
@activities = StudentActivitiesDecorator.decorate_collection(@activities)
end
end
装饰器还必须包括decorates PublicActivity::Activity