鉴于我有一个嵌套在 Farm 模型下的 Worker 模型,我如何在 Workers 控制器(称为 FarmWorkersController)中正确加载 Worker 资源?我试过这个...
class FarmWorkersController < ApplicationController
load_resource :farm, :parent => true
load_resource :class => 'Worker', :through => :farm, :parent => false
# Note that :parent and :class need to be specified on the Worker resource line,
# as the name of the controller (FarmWorkersController) is different from Worker model name
end
...但我得到了错误
undefined method `farm_workers' for #<Farm:0xa87670c>
请注意,如果我在返回工人集合的 Farm 模型中定义了一个 farm_workers() getter,那么我不会收到错误消息——尽管没有为索引操作加载 Workers 集合。无论如何,我不想污染我的模型以使控制器身份验证工作。
(没关系,但我使用的是 mongoid)