Constrain a route to a specific host
If you have two hosts that point to one rails app, like apple.myapp.com
and orange.myapp.com
and you'd like a specific route to only be availabe on orange
then you can constrain the route based on the host like this:
constaints(host: 'orange.myapp.com') do
get '/thing/:id', to: 'thing#show'
end
And if you had additional host for banana
that should also get this route:
constaints(host: ['orange.myapp.com', 'banana.myapp.com']) do
get '/thing/:id', to: 'thing#show'
end
But in this case only the subdomain differs so we can do this:
constaints(subdomain: ['orange', 'banana']) do
get '/thing/:id', to: 'thing#show'
end
Tweet