Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 重构:具有父级失败的嵌套资源_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 重构:具有父级失败的嵌套资源

Ruby on rails 3 重构:具有父级失败的嵌套资源,ruby-on-rails-3,Ruby On Rails 3,我有以下资源设置: resources :sites do resources :documents # more nested here end resources :documents do resources :notes, :except => [:show, :new, :edit] end 我希望notes控制器具有文档上下文。问题是,文档控制器本身取决于站点上下文。因此,从上面创建的/document URL都会抛出500个错误。我可以调整控制器代码来处理这

我有以下资源设置:

resources :sites do
  resources :documents
  # more nested here
end


resources :documents do
  resources :notes, :except => [:show, :new, :edit]
end

我希望notes控制器具有文档上下文。问题是,文档控制器本身取决于站点上下文。因此,从上面创建的/document URL都会抛出500个错误。我可以调整控制器代码来处理这个问题,但我想知道是否有办法不创建/document URL,只创建:/document/#id/notes

对于可能存在此问题的任何其他人,您可以使用:来限制您不想要的路由,除了@agmcleod用于:notes的方式。因此,要限制文档URL,可以选择:

resources :sites do
    resources :documents, :except => [:index, :show, :new, :create, :edit, :update, :destroy]
    # more nested here
end


您可以根据需要删除任何操作。

必须承认,我在这里记不太清楚我的问题,因为它是从11月份回来的。后来我对我的模型进行了一些重构,现在我有了文档>版本>注释,实际上我就是这么做的。使用except选项仅加载父资源所需的几个路由。我接受了你的回答,因为它是正确的。
resources :documents, :except => [:index, :show, :new, :create, :edit, :update, :destroy] do
    resource :notes, :except => [:show, :new, :edit]
end