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.
Asked
Active
Viewed 173 times
1 Answers
2
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

Tarscher
- 1,923
- 1
- 22
- 45