I am writing a web app which works on subdomains. I would also like to add custom domains so users can create a CNAME so their domain (hello.com) goes to their subdomain (123.hellothere.com).
How would I go about going this with Ruby on Rails?
I already have subdomains working fine on my app, I just seem to be having problems with adding custom domains.
I have subdomain and custom_domain in the database relating to the users blog.
I have tried following this tutorial – http://glacialis.postmodo.com/posts/cname-and-subdomain-routing-in-rails – with no luck.
EDIT
subdomain and custom_domain are attached to the Blog model. For the subdomains I used this tutorial at RailsCasts
I don’t know how you have your subdomains set up but you should have some code which looks like this somewhere:
This code is just a proof of concept. You should make sure that you a) protect against people stealing each others domains (uniqueness check on the custom_domain parameter) and b) make sure that they don’t enter your domain into the custom_domain field allowing them to have multiple “local” domains.
Edit: you should also make sure that, if the
current accountmethod is defined on a controller, that you memoize it with a@current_account ||=to avoid un-necessary calls to the database.