I was recently tasked with segregating my existing Rails 3 application into a standard and premium version. The premium version will have all the existing functionality with the addtion of a new layout, and new functionality. Ideally I want premuim users to access this site byway of prefixing the current url with a subdomain, e.g, “premium.somesite.com”/ The standard version of the website I don’t want to change and is still accessible by the default url.
If possible I would like to simply add some logic to exiting views and controller to determine how the request is treated on whether or not a subdomain is being used .
I tried following the Railcast subdomains in rails 3, however he’s using subdomains in context of a blog model and database attributes where as I wanted mine to be application-wide. Is this even possible with subdomains? How can I get started?
What I’ve tried:
Added an additional VirtualHost to my apache httpd.conf file used by passenger:
<VirtualHost *:80>
ServerName premium.mydomain.com
DocumentRoot /somewhere/../myapp
<Directory /somewhere/public>
Allow from all
Options -Multiviews
</Directory>
</VirtualHost>
Added the following to my routes.rb
class PremiumSubdomain
def self.matches?(request)
request.subdomain == "premium"
end
end
MyApp::Application.routes.draw do
constraints(PremiumSubdomain) do
#all of my routes...
end
end
What happens:
Trying to navigate to my site with the premium subdomain results in a domain not found, adding the constraint to my route.rb prevents the rest of the application from rendering anything on my default url.
So it turned out that while I did have everything configured on apache appropriately we were using a third-party for our DNS server so it was simply a matter of adding a record for our sub-domain and everything else was peachy.