views:

34

answers:

1

Hi folks, I want the check a belongs_to model for permission. A user should only create a blog, if he is the owner of the project

Model Code

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

And now the relevant Authorization part

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

The if_attribute is the problem, how do I check the related model? (The above if_attribute codeline doesn't work because blog belongs_to project and the user_id is in the project_model)

Thanks in advance :)

A: 

Thanks to the creator,

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