我想要检查一个 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 中)
提前致谢 :)