2010-07-20 21 views
1

我想檢查一個belongs_to模型的權限。用戶應該只創建一個博客,如果他是該項目的業主如何在declarative_authorization文件中檢查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代碼行沒有因爲博客belongs_to的項目工作和user_id是在project_model)

感謝提前:)

回答

1

感謝造物主,

if_attribute :project => {:user => is {user}}