On 12 May 2013 09:34, Polly Hay <li...@ruby-forum.com> wrote:
> Hello
>
> I am new to rails and have a design issue. Although I have a proposed
> solution I am far from sure how robust it is. I would appreciate any
> feedback.
>
> My application is team based:
> - A user can only be in one team
> - Team members(user) cannot view/edit another team's content
>
> Team A
> -User
> -Widget
> --Part
>
> Team B
> -User
> -Widget
> --Part
>
> I need to:
> - identify the team from the user
> - create members for a team
>
> So everything is simple - just create a User model that belongs_to the
> Team (has_many users). Except I need admin users to manage the teams. My
> problem is how best to manage this?
>
> I think I need a User model and a Member model. The user handles
> authentication, a user without a member association is an admin and the
> member belongs to the Team. Perhaps something like this:
>
> Team
> has_many :members
>
> Member
> belongs_to :team
> has_one :user
> attr :team_role
>
> User
> belongs_to: member
> authenticates!
> attr :admin_role
>
> However, this doesn't seem correct because the User still belongs to
> Team. I am sure that at least the relationship between user & member is
> incorrect. Can you suggest a better (more conventional) solution?

Keep it simple, just have one user table with a flag to say whether it
is an admin user or not.  This would also allow an admin user to be a
member of a team.  You could look at the cancan gem which will handle
multiple roles but that is probably overkill for this case.

A question, can a user be in more than one team?  If so then you will
need a different setup.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to