2013-04-11 113 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

相關問題