Custom Subdomains in Rails 3
Stephan Kaag wo 23 jun 10
Rails 3 supports subdomains out of the box, which is great. But did you know that the constraints in the Router can actually match patterns too? This means instead of hardcoding each subdomain into your routes you can allow your customers to decide their own subdomains.
I created a ‘lib/sub_domain.rb’ with the following code:
class AdminSubdomain def self.matches?(request) subdomain = request.subdomain ['admin', 'backend', 'adminpanel'].include? subdomain end end
In my routes.rb file I can now wrap all routes I want under a custom subdomain
# config/routes.rb TestApp::Application.routes.draw do |map| constraints(AdminSubdomain) do get "admin/index" end root :to => "home#index" end
The admin panel is now reachable at all three subdomains.
Gepost in hor | 0 reacties
Welcome to Holland On Rails
This weblog is the official Ruby techblog from the guys at Holder, a Ruby development company. Holder is also the company behind the RubyAndRails Europe Conference in Amsterdam.Recente Jobs
Bekijk alle jobs »»
Gereedschapskist
Onmisbare tools vooriedere developer!
- Ruby On Rails
Framework voor de web 2.0 developer. Eindelijk vooruitgang! - TextMate
Editor for true pro's
Typ, tab, top :-)
Nee, niet voor Win. - Made On A Mac
En nou is het over met die saaie grijze Windows bak van je!
Auteurs op deze site
Chris Obdam
'Less is more' evangelist, past dit ook dagelijks toe op zijn tandenborstel.Chiel Wester
Snelheidswonder op Ruby wielen. Leuk om mee te pair-programmen ;-)
Plaats je reactie