I have a controller Partners that I want to server off of http://partners.example.com
-
Is there something built into Rails 3.1 that I can use for this without messing with
httpd.confor creating another virtualhost? -
What would the routes.rb entry look like for this?
Any help would be greatly appreciated.
PS. I’m not doing wildcard subdomains here — just that one single subdomain.
UPDATE: I’ve gotten the subdomain to work with Ahmish’s solution below, but now all other routes also respond on that subdomain. Is there a way I can have the subdomain respond exclusively to the controller specified?
Indeed you can.
If the PartnersController is a REST based controller, it is as simple as adding a constraints option to the call to
resources.Alternatively,
constraintscan be called with a block, and all routing calls inside the block will be subject to the set subdomain constraint.Requests to the constrained URLs without the correct subdomain will throw a
RoutingError.