【发布时间】:2012-02-21 03:32:03
【问题描述】:
我对 cancan 和嵌套路由有一些问题。
我有这条路线:
resources :companies do
resources :projects
end
我对公司模型的能力没有问题,但对于项目模型,如果他们不是公司的管理员,我想拒绝对 Project#index 的访问。
下一个代码有效:
can :show, Company do |company|
if user.admins.include?(company) #check if the user is admin of the company
can :index, Schedule, :company_id => company.id
end
end
但我该怎么做:
can? :index, Project
我尝试过重命名这样的方法:
can :index_projects, Company do |company|
if user.admins.include?(company) #check if the user is admin of the company
can :index, Schedule, :company_id => company.id
end
end
并使用:
can? :index_projects, @company
但它不起作用。你知道怎么做吗?
谢谢。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 cancan