2
我有以下途径:继承的资源和可选的belongs_to:如何范围集合在父资源,但不是在嵌套的资源?
resources :boilerplates
resources :projects do
resources :boilerplates
end
的Boilerplate
模型是这样的:
class Boilerplate < ActiveRecord::Base
scope :originals, -> { where(prototype_id: nil) }
end
我的控制器看起来是这样的:
class BoilerplatesController < InheritedResources::Base
load_and_authorize_resource
belongs_to :project, optional: true
end
当URL /boilerplates
被打开,我要显示范围为originals
的所有样板。
当URL /projects/123/boilerplates
被打开时,我希望originals
范围不被激活。
这是如何实现的?