Search code examples
ruby-on-railssaas

How to use apartment gem for saas app on localhost without lvh.me?


How to implement tentant to go to url like:

localhost:3000/tenent1

instead of using lvh or any domain or subdomain like:

http://tenent1.lvh.me:3000
tenent1.example.com 

or

tenent1.com 

where tenent1 is one of the tenent created by user on the signup process. I dont want to use subdomain, domain.


Solution

  • Apartment gem has an initializer file where you can create any kind of elevator you want. I guesss you don't want the subdomain one, so you can write an elevator that would check first route part (e.g. localhost:3000/tenant1/)

    For more info see Apartment intializer file.

    I guess in your case it would be something like this (add this in your apartment initializer file)

     Rails.application.config.middleware.use 'Apartment::Elevators::Generic', lambda { |request|
       request.path.split('/')[1] # First element will be an empty string
         }