Skip to main content

Build Multitenancy App in a different way

General • Asked by Stan X
I have seen many questions and topics in gorails about multitenancy but I am a bit undecided about which way to go. 

I would like my app not to carry the subdomain name in the url. Indeed, I would like users to be able to switch between several accounts as long as he has been entitled by the admin of the account (subdomain). So user A can be admin of X, Y and be simple user of Z (entitled by another admin). Permission would be read from a central place - dedicated database?- and visibility/edition/destruction of content items (eg. contacts, files...) would be based upon these rights. Ideally - but that would be the cherry on the cake - each account and content items- would be insulated in different databases- the reasons for this is that i could read some info into different storage places (in a far far future) - including locally. 

Turning over to GoRails community and Rails experts. feel free to join the discussion. 

when i say 'accounts' it can be companies, schools, it ;-)

So this gets a little bit tricky since you're essentially wanting an organizational feature with split databases.  I'm not sure how to pull this off with the separate databases as I've always used PG split schemas agnostic of the subdomain.

But if you're ok with keeping all tenant/user data in single database you could go with scopes and a mix of authorization (roll your own or choose pundit or something like that).  I know that Rails 6 will support multi-databases baked into AR, but I don't think we're there yet, but someone else may be able to chime in.

If you could bullet point your specs, I might be able to get a clearer picture and offer a bit more insight.

We have implemented a multitenancy app with the Acts As Tenant gem ( and Devise, where a User can have Memberships in multiple Organizations. Users eligible for managing other Users (you my call them Admins) can 'invite' Users from other Organizations to join, so that they can switch between those Organizations. No subdomains used.

Essentially a User has_many Memberships (and Organizations through Memberships). An Organization has_many Memberships (and Users through Memberships). And a Membership belongs_to an Organization and User.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.