UPDATE: I’ve built a slice that implements this behavior in a cleaner fashion. merb-auth-slice-multisite
Here’s how to handle dynamic subdomains in Merb in the router.
1 # in your view (or controller) 2 <%= request.first_subdomain %> 3
1 # in router.rb 2 Merb.logger.info("Compiling routes...") 3 Merb::Router.prepare do 4 5 module Merb 6 class Request 7 def first_subdomain 8 subdomains.first 9 end 10 end 11 end 12 13 resources :accounts 14 15 # This passes the domain to the params[:account] value 16 match(:first_subdomain => ":first_subdomain") do 17 resources :pages 18 end 19 20 end
Spitfire Sky | github | archives | resume