0

Can we have multi-level subdomain in Rails like this?

sub1.sub2.mysite.com
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Saim
  • 2,471
  • 5
  • 30
  • 43

2 Answers2

2

Yes, you can check the subdomain the app is accessed from using request.subdomains

But if you are going to do something more advanced you should probably use subdomain-fu

Roger Ertesvag
  • 1,784
  • 2
  • 14
  • 15
0

I don't see any reason why you couldn't have a subdomain of a subdomain being used in a rails app.

You'll want to setup a wildcard A record in your domain DNS and configure your http server to accept wildcard server aliases.

Then in your application_controller you'll probably want a before_filter that does some juju with

request.host

to do whatever you want, be it

Account.find_by_domain(parsed_request_host) or whatever.

Mark Connell
  • 3,739
  • 1
  • 16
  • 11
  • 1
    Roger/Mark, thanks for the reply. Well, now it clear to me that we can achieve multi-level sub-domains. Let me proceed a bit further with my actual requirement. In my Rails application a user can have multiple categories and then multiple items associated with one category. Consider the following scenario: Domain:site.com Group:G1 Items:i1,i2 Group:G2 Items: i1,i2 Now,the requirement is to have a different URL for each item. Considering the above data we'll have following URLs: http://i1.G1.site.com http://i2.G1.site.com http://i1.G2.site.com http://i2.G2.site.com Please advise. – Saim Sep 09 '09 at 15:47