在我的应用程序中,所有用户都可以在那里阅读自己的任务。第二个控制器仅供版主使用,版主可以查看所有任务。
# accessible for every user
# every user should see only own tasks,
# but at the moment all moderators see all tasks
class TasksController < ActionController::Base
load_and_authorize_resource
end
# only accessible for moderators, all tasks
class TasksModeratorController < ActionController::Base
load_and_authorize_resource :task, :parent => false
end
# Ability
# Moderators can read all tasks
if user.moderator?
can :read, Task
end
# All users can read there own tasks
can :read, Task, :user_id => user.id
我如何限制 TasksController 中的任务只向版主显示自己的任务,但 TasksModeratorController 中的所有任务?还是有更常见的方法来处理这个?