Module: SubdomainRouter::Controller
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/subdomain_router.rb
Overview
Controller mixin that adds subdomain management features.
Instance Method Summary collapse
-
#url_for(options = {}) ⇒ String
Adds to the ‘url_for` method the ability to route to different subdomains.
Instance Method Details
#url_for(options = {}) ⇒ String
Adds to the ‘url_for` method the ability to route to different subdomains. Thus, all URL generation (including smart route methods) gains the `:subdomain` options.
For more information, see the Rails documentation.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/subdomain_router.rb', line 27 def url_for(={}) return super unless .is_a?(Hash) case [:subdomain] when nil .delete :subdomain super when false, String subdomain = .delete(:subdomain) || Config.default_subdomain host = [:host] || (respond_to?(:request) && request.host) || Config.domain host_parts = host.split('.').last(Config.tld_components + 1) host_parts.unshift subdomain host_parts.delete_if &:blank? super .merge(host: host_parts.join('.')) else raise ArgumentError, ":subdomain must be nil, false, or a string" end end |