Skip to content

Instantly share code, notes, and snippets.

@Fonsan
Created March 13, 2011 17:09
Show Gist options
  • Save Fonsan/868266 to your computer and use it in GitHub Desktop.
Save Fonsan/868266 to your computer and use it in GitHub Desktop.
Ugly non threadsafe way of routing a subdomain to a controller
class SupportSubdomain
def self.subdomain
@@request.subdomain.to_sym rescue :not_found
end
def self.matches?(request)
@@request = request
request.path_parameters[:controller] = request.subdomain
Rails.logger.info request.path_parameters[:controller]
request.subdomain.presence
end
end
Subroutes::Application.routes.draw do
c = Class.new SupportSubdomain
constraints(c) do
controller c.subdomain do
match "(:action)"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment