I am trying to build a multi-location app from a client. I have tried dabbling with Apartment and other types of multitenancy but didn't receive a proper result.
The app should have domains for each location as follows:
e.g. example.com/newyork, example.com/boston
I can't use subdomains, as they will be used for languages.
e.g. en.example.com/newyork, es.example.com/newyork
Each location will have a model showing content and search functionality for that location only.
e.g. When in newyork, boston posts won't be shown and when in boston, new york posts won't be shown.
However, a user has a single sign-on for all locations and languages, and a user can view all content posted within the app regardless of the location. If I use multitenancy, the user can only view New York posts when on /newyork and Boston posts when on /boston which is not the desired result.
What approach should I follow here? Does multitenancy even make sense?
This isn't entirely related, but did you know you can actually use multiple subdomains? It's rare and makes things more complicated, but you can do en.newyork.example.com if you wanted. I wouldn't recommend it, but fun fact. :)
I wouldn't recommend using multi-tenancy for this, but rather just scoping your results.
You'll want to setup the routes so that the first part of the URL is matched for the location, then you can lookup a Location record in your database, and scope all your controllers to
@location. That way you'll get the effect of multi-tenancy but without the trouble by just making sure you reference
@location.posts for example instead of
Plus you won't have to worry about single sign-on because that only matters between separate domains generally.
Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.