Module: ActionDispatch::Routing::Mapper::Subdomains

Defined in:
lib/subrails/action_dispatch/routing/mapper/subdomains.rb

Instance Method Summary collapse

Instance Method Details

#redirect_to_subdomain(subdomain, path = '/', &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/subrails/action_dispatch/routing/mapper/subdomains.rb', line 15

def redirect_to_subdomain subdomain, path='/', &block
  redirect{ |params, req|
    path          = block.call(params, req) if block
    path          = path % params
    uri           = URI.parse(path)
    uri.scheme    = req.scheme
    uri.host      = req.host
    uri.subdomain = subdomain
    uri.port      = req.port unless req.standard_port?
    uri.to_s
  }
end

#subdomain(*subdomains, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/subrails/action_dispatch/routing/mapper/subdomains.rb', line 6

def subdomain *subdomains, &block
  subdomains = subdomains.map(&:to_s)
  if subdomains.length == 1
    constraints(:subdomain => subdomains.first, &block)
  else
    constraints(lambda{ |req| subdomains.include? req.subdomain.to_s }, &block)
  end
end