3

私のアプリでは、シートコントローラーがあり、モデル名はSheetですが、ルートは次のとおりです

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

そのため、url は magazine/page/1/article... になります。

Article コントローラーで、シートの load_and_authorize_resource を呼び出して、関連するシートの記事にアクセスできるようにする方法。私は試した

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

@sheet.articles にアクセスできません......

4

1 に答える 1

8

次のいずれかがあります。

 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 
于 2013-04-11T07:52:50.647 に答える