I’m trying to figure out how to set up the relationship/association for a Document model for my rails project. I have a User model and Users can friend each another (friendship model).
Now I want users to be able to invite (give access to) CERTAIN friends to modify and edit these documents similar to Google Docs.
This is my current approach to this problem:
Create a new relationship model called “group”, essentially a subset of friends. Document belongs to a user and document belongs to a group. Users can then invite their friends into these group relationships and documents can be accessed/modified through these groups.
Therefore, User has many groups and group belongs to many users.
My question:
- Is there a better approach to this problem?
You might consider a “Membership” join table. So:
…since you requirement is some users will have abilities others wont (editing). There are all sorts of options from there, for example STI which would give you:
And a controller class something like
As an example, depending on your opinion of STI.
https://github.com/scambra/devise_invitable
might have more ideas.