views:

340

answers:

2

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

sub1.sub2.mysite.com

Imran

A: 

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
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.comGroup:G1 Items:i1,i2Group:G2 Items: i1,i2Now,the requirement is to have a different URL for each item. Considering the above data we'll have following URLs:http://i1.G1.site.comhttp://i2.G1.site.comhttp://i1.G2.site.comhttp://i2.G2.site.comPlease advise.
Imran
+1  A: 

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