【问题标题】:How can i setup load_and_authorize_resource through a habtm association?如何通过 habtm 关联设置 load_and_authorize_resource?
【发布时间】:2012-04-07 11:14:51
【问题描述】:

我有想要在项目上下文中显示的任务。它们通过 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
  ...

【问题讨论】:

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


    【解决方案1】:

    你可能想让你加入一个模型,这样一个项目has_many :tasks, :through =&gt; : assignments

    【讨论】:

    • 我会试试这个,也许这就是要走的路。
    猜你喜欢
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多