How can I create in real-time a new URL path in Ruby on Rails?
For example: I want my users to have name.XXX.com or XXX.com/name.
FYi I'm hosting the code on Heroku.
How can I create in real-time a new URL path in Ruby on Rails?
For example: I want my users to have name.XXX.com or XXX.com/name.
FYi I'm hosting the code on Heroku.
Have a look at subdomain-fu plugin.
https://github.com/mbleigh/subdomain-fu
The easiest solution is like tadman described: set up a DNS record and write a rewrite rule for Apache/nginx/whatever which will eat subdomain and add it to params.
As an option, set up a middleware (more about it http://guides.rubyonrails.org/rails_on_rack.html), where you can rewrite/route the requests before the get processed by Rails routing. Being prepared carefully, this can help implementing very sophisticated things :)
I would checkout some previous answers for 'vanity' urls in the case for example.com/username:
How can I implement vanity URL's in a Rails application?
How to implement "short" nested vanity urls in rails?
As for subdomains, other suggestions by @Arkan, @Anton, @tadman are a good starting point.
You'll need a wildcard CNAME or A record to point your names over in the first place, which in this case would be
*.XXX.com
, to handle this on a DNS level. The second part is in examining yourrequest.host
header which will bename.XXX.com
or whatever is used. You can use this to set variables in abefore_filter
block.