0

I have 2 subdomains that point to one rails application. My rails application's controllers should serve both subdomains.

Lets call the subdomains www.mydomain.com and demo.mydomain.com. I want 2 to accomplish 3 things:

  1. Make sure only some of my controllers serve www.mydomain.com and some serve both domains.
  2. Make sure only a subset of my controllers' actions serve www.mydomain.com and some serve both domains.
  3. 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 www.mydomain.com (e.g. http://www.mydomain.com/index.json).

What's the best way to accomplish both requests ?

refaelos
  • 7,927
  • 7
  • 36
  • 55

1 Answers1

1

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

@host = request.host
Community
  • 1
  • 1
arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
  • 1
    You could look at http://stackoverflow.com/questions/5382248/ruby-on-rails-routes-rb-match-file-extension-when-multiple-periods-exist-in to route using requested extension or use something like request.fullpath.match(/html$/) or request.fullpath.match(/json$/) – arcyqwerty Jan 01 '12 at 18:13