Hi GoRails friends,
I have a list of products. Products can be created by users. So far so good.
Now, I would like to allow some users to be part of companies (0, 1 or several).
One user (the admin for the company) to invite users to be 'part' of his/her company.
When part of the company, the user will be able to create products on the name of the companies he/she belongs to (in addition to create products on his/her own but that somehow a detail).
Not sure how to split this out to start - including using gems like invitable (examplified by Chris) for the invitation system.
So it sounds like you have a join table possibly missing called company_employees or company_users that would allow users to belong to multiple companies. That should give you the base foundation for users being able to pull a list of their companies and a company knowing all of it's users.
As far as invitations are concerned there are a few ways to do this. One way is to create a model called company_invitation that has a inviter_id, user_id, company_id, token:string, and accepted:boolean. This would give you the ability to send out unique links (with token) that users can click to accept invitations.
So far so good right? We have the data tied together between users and companies and the data storage for how to invite users to those companies...cool.
The next part is just a little bit harder. Basically you would have a UI where a user would enter an email address and click "invite". The controller/business-logic needs to determine if that email belongs to an existing user or not. If it does you can just send that user a link that they click and the logic to handle that is as simple as marking the invitation as accepted and assigning the user_id to it (for tracking purposes) and creating that company/user join model we discussed earlier. However...if the email address does not belong to the user than that "accept" page has to be less automatic. Instead of simply accepting, we have to collect the fields required by a user so we can create one, then post that form to the controller and create/validate the user, accept the invite, and send them on their way.
I hope this helps, but if you need more deets then hit me up on the slack GoRails community or on here.
Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.