Rails 7 #115 Multitenancy, Teams and Roles without a gem

03/03/2023 (about 1 year ago)
Mulitenancy multi-tenant architecture multi tenant architecture saas Aws multitenancy definition how multitenancy works learn about multitenancy devise gem ruby on rails devise authentication rails devise ruby on rails tutorial ruby on rails devise gem install devise invitable Ef core mult-tenant software architecture multitenancy tips Teams and Roles without a gem

Ruby on Rails #115 Multitenancy, Teams and Roles without a gem

Want to learn more on the topic?
Here's a DISCOUNT for my complete course Ruby on Rails: Learn to Build a Multitenancy SaaS app: https://yshmarov.gumroad.com/l/ror6saas/presale33

In this episode we will:

  • let users register
  • let users create tenants/accounts/organizations/workspaces
  • user who created tenant automatically becomes admin
  • invite users to become members of the app
  • invited users are not admins
  • allow only members to access parts of the app scoped to the tenant

Setting tenant based on routes is the best, because you can have multiple tenants open in different tabs (unlike adding current_tenant_id current_user).
Second best option is subdomain multitenancy, but that is harder to pull off and maintain.
Row-based multitenancy is the most popular choice, and it is used in Rails SaaS starterkits like Bullettrain and Jumpstartpro.

Episode source code: https://github.com/corsego/116-multitenancy-routes-rows/commits/main
Database architecture: https://dbdiagram.io/d/63fbe3ed296d97641d83db94

0:00 Multitenancy examples
4:35 static pages controller
6:28 install devise
8:48 scaffold tenants
10:31 generate members resource
12:34 tenant creator becomes admin member, member authorization
16:12 install devise invitable
17:31 diplay tenant members
20:20 invite users to be members of tenant
26:42 member authorization
28:50 Final demo and thoughts

Sign in to join the conversation