Reputation: 684
I have a domain, domain.com, and I want one Rails application, for example, to handle all subdomain requests, i.e., blog.domain.com, subdomain.domain.com, etc.
The Ruby on Rails framework is all about convention. So, is there a convention for creating subdomains in Rails? If so, what is it? If not, what might be some good methods for trying to get what I described above accomplished?
Upvotes: 2
Views: 1335
Reputation: 5644
You could follow this tutorial on using subdomains in Rails: http://railsapps.github.io/tutorial-rails-subdomains.html
Basically, you implement routing for subdomains like this:
match '/' => 'profiles#show', :constraints => { :subdomain => /.+/ }
Url helper methods also accepts a subdomain option so you can write url helpers like:
link_to root_url(:subdomain => user.name), root_url(:subdomain => user.name)
You'll find more details as to how to use subdomains in the link provided above.
Upvotes: 2