1

我想要检查一个 belongs_to 模型以获得许可。如果用户是项目的所有者,则只能创建博客

型号代码

User
  has_many :blogposts
  has_many :projects
end

Project
  has_one :blog
  belongs_to :user
end

Blog
  has_many :blogposts
  belongs_to :project
end

Blogpost
  belongs_to :user
  belongs_to :blog
end

现在是相关的授权部分

User  has_permission_on [:blog], :to => [:create, :new, edit, :update] do
 if_attribute :project_user_id => is {user.id}
      end

if_attribute 是问题,我如何检查相关模型?(上面的 if_attribute 代码行不起作用,因为 blog belongs_to 项目和 user_id 在 project_model 中)

提前致谢 :)

4

1 回答 1

1

感谢创作者,

if_attribute :project => {:user => is {user}} 
于 2010-07-20T19:17:52.217 回答