Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Inherited Resources

ryanb edited this page Oct 6, 2010 · 10 revisions

As of 1.4, the load_and_authorize_resource call will automatically detect if you are using Inherited Resources and load the resource through that. The load part in CanCan is still necessary since Inherited Resources does lazy loading. This will also ensure the behavior is identical to normal loading.

class ProjectsController < InheritedResources::Base
  load_and_authorize_resource
end

if you are doing nesting you will need to mention it in both Inherited Resources and CanCan.

class TasksController < InheritedResources::Base
  belongs_to :project
  load_and_authorize_resource :project
  load_and_authorize_resource :task, :through => :project
end