All threads / Building a multi-location app in rails

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Building a multi-location app in rails

Satchit Shenoy asked in General

Hi!

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 Post.all.

Plus you won't have to worry about single sign-on because that only matters between separate domains generally.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.