Reputation: 759
In my app, I have sheets controller, model name is Sheet but my routes are as below
routes.rb
namespace :magazine do
resources :pages, :controller => "sheets" do
resources :articles do
resources :comments
so that url will be magazine/page/1/article...
In my Article controller how to call load_and_authorize_resource for sheets so that I can access article of the related sheet. I tried
load_and_authorize_resource :sheet, :class => 'Sheet', :parent => false
load_and_authorize_resource :through => :sheet
Cannot access @sheet.articles......
Upvotes: 3
Views: 4578
Reputation: 115541
Either you have:
load_and_authorize_resource :page, :class => 'Sheet', :parent => false
And you access your data with @pages
Or you replace with:
load_and_authorize_resource :sheet, :class => 'Sheet', :parent => false
And you access your data with @sheets
In ArticlesController, to get both sheet
and articles
:
load_and_authorize_resource :sheet, :class => 'Sheet'
load_and_authorize_resource :article, :through => :sheet
Upvotes: 8