2013-04-11 142 views
1

在我的应用程序,我有张控制器,型号名称是表,但我的路线是如下惨惨的load_and_authorize_resource当资源名称是从模型/控制器名称不同

routes.rb 
namespace :magazine do 
    resources :pages, :controller => "sheets" do 
    resources :articles do 
    resources :comments 

使URL会杂志/页/ 1/article ...

在我的文章控制器中,如何调用表单的load_and_authorize_resource以便我可以访问相关工作表的文章。 我试图

load_and_authorize_resource :sheet, :class => 'Sheet', :parent => false 
load_and_authorize_resource :through => :sheet 

无法访问@ sheet.articles ......

回答

4

要么你有:

load_and_authorize_resource :page, :class => 'Sheet', :parent => false 

而且你@pages

或者你访问你的数据替换为:

load_and_authorize_resource :sheet, :class => 'Sheet', :parent => false 

而且你@sheets


在ArticlesController,访问您的数据,同时获得sheetarticles

load_and_authorize_resource :sheet, :class => 'Sheet' 
load_and_authorize_resource :article, :through => :sheet 
+0

还是一样..... load_and_authorize_resource:板材,:类=>' Sheet',:parent => false load_and_authorize_resource:through =>:sheet不起作用 – Oatmeal 2013-04-11 09:01:51

+0

为什么你需要'parent'? – apneadiving 2013-04-11 09:08:25

+0

在哪个控制器中,你是否想要数据? – apneadiving 2013-04-11 09:09:43

相关问题