I have 2 subdomains that point to one rails application. My rails application’s controllers should serve both subdomains.
Lets call the subdomains http://www.mydomain.com and demo.mydomain.com. I want 2 to accomplish 3 things:
- Make sure only some of my controllers serve http://www.mydomain.com and some serve both domains.
- Make sure only a subset of my controllers’ actions serve http://www.mydomain.com and some serve both domains.
- Make sure users use only format :html for demo.mydomain.com (e.g. http://demo.mydomain.com/index.html) and use only formats :json/:xml for http://www.mydomain.com (e.g. http://www.mydomain.com/index.json).
What’s the best way to accomplish both requests ?
Perhaps take a look at request routing based on subdomain
How do I route by domain / subdomain in rails
http://agilewebdevelopment.com/plugins/request_routing
where the request_routing plugin would allow you to define routing requirements that test methods/properties of the request object such as subdomain, domain, port. You can test them either against a value or with a Regexp (assuming the method returns a string).
If you’re using rails 3 you could also check out subdomaining your rails site
http://railscasts.com/episodes/221-subdomains-in-rails-3
In order to get your controllers to respond differently based on subdomain, you can use a conditional based on