Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

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.

Chris Seelus,

I have tried over and over to get Acts_as_tenant to work with devise and opperate correctly but cannot get it to function together. Do you have any suggestions or places to look at a functioning codebase? I have managed to work with Devise quite well and be fine with that, but adding AAT starts causing problems looking for the tenant or account.


Hey Brendan, I have used activerecord-multi-tenant gem ( that has worked really well and is built on top of acts_as_tenant. It's row based multi-tenancy and works well with Devise too.

as @tabish said, activerecord-multi-tenant gem is super simple to work with and works really well if your looking for a non partitioned approach!

Apartment uses a different schema for every tenant
You get a wayt better data isolation than the other existing solutions. Subdomain use is not ultimately required (see end of post)

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ 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.