I have three models, one for Projects, other for Users and other to the has_many :through called Projectzation.
The Projectzation migration looks like this
class CreateProjectzations < ActiveRecord::Migration
def change
create_table :projectzations do |t|
t.references :user, :project
t.boolean :admin
t.timestamps
end
end
end
Then, to create the association i do like this
user.projectzation.create(:project => project, :admin => true)
By setting admin=true, I say that the user is an adminstrator of the project.
How to know if the user is an adminstrator? Maybe something like this
project.is_admin_user?(@current_user)
has_many :throughis here a m:n relationship betweenprojectsandusers. So the question has to be all the time: “Is a user an admin user for a project?”So your call
project.is_admin_user?(@current_user)(in the context ofUsersController) is meaningful.A possible implementation could be:
You could add
so it could be asked in both directions.
In my opinion, there are three cases: