I have public and private projects in my app. I want to assign user to private projects for viewing and posting. What's the right way to do this? I tried with a permissionlist model and associated it to a project. but i got so confused that i couldn't make it.
+1
A:
What you need is a has_many :through relationship
Create a table
permissions
containing
user_id, project_id and permission
.
your models
class Permission < ActiveRecord::Base
belongs_to :user
belongs_to :project
end
class User < ActiveRecord::Base
has_many :permissions, :dependent => true
has_many :projects, :through => :permissions
end
class Project < ActiveRecord::Base
has_many :permissions, :dependent => true
has_many :users, :through => :permissions
end
in the permissions link the project, user and the permission the user has on that project.
I hope this helps.
Regards, Stijn
Tarscher
2009-06-23 13:43:40
i'll read the :through relationship from the docs, thank you
imit
2009-06-25 21:10:01