Module: ActionDispatch::Routing::Mapper::HttpHelpers

Defined in:
lib/action_dispatch/routing/mapper/http_helpers.rb

Instance Method Summary collapse

Instance Method Details

#ensure_no_wwwObject Also known as: ensure_non_www, ensure_apex



2
3
4
# File 'lib/action_dispatch/routing/mapper/http_helpers.rb', line 2

def ensure_no_www
  ensure_subdomain ''
end

#ensure_on(environments) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/action_dispatch/routing/mapper/http_helpers.rb', line 12

def ensure_on(environments)
  environments.each_pair do |env, domain|
    if Rails.env.to_sym == env
      ensure_subdomain domain
    end
  end
end

#ensure_subdomain(subdomain, options = {}) ⇒ Object Also known as: ensure_subdomains



20
21
22
23
24
25
26
27
# File 'lib/action_dispatch/routing/mapper/http_helpers.rb', line 20

def ensure_subdomain(subdomain, options={})
  redirector = ::EnsureSubdomain.new( subdomain )
  verbs = options[:via] || [:get, :post, :put, :patch, :delete]
  constraints( redirector ) do
    match '/', to: redirect { |params, request| redirector.to params, request }, via: verbs
    match '/*path', to: redirect { |params, request| redirector.to params, request }, via: verbs
  end
end

#ensure_wwwObject



8
9
10
# File 'lib/action_dispatch/routing/mapper/http_helpers.rb', line 8

def ensure_www
  ensure_subdomain 'www'
end