Addition to the Dinesh Saini answer - you also need to update your Rails configuration accordingly. For example, if you need deep subdomains, you should change config.action_dispatch.tld_length to staging.rb, and you should double-check route.rb.
Live example: I had to implement store display by subdomain - example URL my-shop.shop.testapp.com. So what I did, except for server configuration changes
constraints (lambda { |req| req.subdomains[1] == 'shop' }) do get '/', to: 'shopes#show', as: :shop end
In the controller to search for a resource
Shop.find_by(id: request.subdomains[0])
I also installed
config.action_dispatch.tld_length = 2
I did this to create env because it has such a staging.testapp.com url, so I need a different subdomain level. I think for you it is only good to check that it has 1.
source share