All threads / Domain & Subdomain Routing Constraints in Rails Discussion
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Domain & Subdomain Routing Constraints in Rails Discussion

@Chris !!!!

THANK YOU! I've been at this all day working with acts_as_tenant. Had some issue with some "undefined method `arity' " error when I added the acts_as_tenant(:account) to a model. Nothing much on the internet - but turned out it was such a simple updating of the gem to resolve it. (just in case anyone else comes across this issue like me). It's 2am here now. Tired. EEEK!

Anyway, thank you so much for explaining the final piece of the puzzle for multi-tenancy domain constraints in detail.. Appreciate it. Cannot wait to try out this with a custom domain on a live site. Going to try host the app using Hatchbox. I normally use Heroku but going to make the switch now.

Savage work dude!!
Bradley.

Reply

This episode is right on time, just what I needed. Quick little detail, around 1:50, I had to do more than set config.hosts =nil. I also had to comment out config.hosts in environments/development.rb before the app would start.

Reply

FYI @chris, you actually can use localhost (well at least on Firefox and Chrome).

localhost will act as the top-level domain, so if in dev you use an URL like: my-subdomain.my-app.localhost:3000, rack will consider the request.subdomain to be my-subdomain. So no need for lvh.me anymore ;)

that was my thoughts too. And on any unix type of operating system that you manage you can also add a few more lines in the hosts file to make it work with any browser as this file is queried before the DNS.

Reply

I recently created a DomainConstraint in an app and used a database query which checks to see if there is a match with any of the saved domains. I do see now that it does add the query to every request but the cost is just a couple of milliseconds. I suppose that I could figure out a way to avoid the database query by caching the saved domain values or instead setting a general constant for the main (i.e. non-custom) domains and doing a non-match against that. I wonder though if it is worth the effort at this point not to mention the added complexity. Are there other hidden costs beyond the few milliseconds I should be considering?

Reply
Join the discussion

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

Join 64,380+ 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.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.