如何通过habtm关联设置load_and_authorize_resource?

时间:2012-03-22 20:27:58

标签: ruby-on-rails ruby-on-rails-3 authorization cancan has-and-belongs-to-many

我想在项目环境中显示任务。它们通过habtm协会联系在一起。所以我有三张桌子:projects, tasks and projects_tasks

resources :projects do
  resources :tasks
end

class Project < ActiveRecord::Base
  has_and_belongs_to_many :tasks
  ...

class Task < ActiveRecord::Base
  has_and_belongs_to_many :projects
  ...

如何通过habtm协会设置load_and_authorize_resource

# ???
class TasksController < ApplicationController
  load_and_authorize_resource :project
  load_and_authorize_resource :task, :through => :project, :shallow => true
  ...

1 个答案:

答案 0 :(得分:0)

您可能希望将表格加入表格has_many :tasks, :through => : assignments