module SubdomainLocale::UrlFor
Public Instance Methods
default_url_options()
click to toggle source
Calls superclass method
# File lib/subdomain_locale/url_for.rb, line 22 def default_url_options super.merge({ subdomain: subdomain_locales.subdomain_for(current_locale) }) end
url_for(options, *other)
click to toggle source
Makes url_for
(locale: 'ru') the same as url_for
(subdomain: 'ru', only_path: false) That way you can easily swap locale in subdomain with locale in the path.
-
assuming you have
scope ":locale"
in your routes:
-
url_for params.merge(locale: 'ru') # => /ru/current_path
After including this module:
url_for params.merge(locale: 'ru') # => http://ru.example.com/current_path
Calls superclass method
# File lib/subdomain_locale/url_for.rb, line 10 def url_for(options, *other) options = options.dup if options.key?(:locale) # Locale specified, force full URL locale = options.delete(:locale) options[:subdomain] = subdomain_locales.subdomain_for(locale) options[:only_path] = false end super(options, *other) end
Private Instance Methods
current_locale()
click to toggle source
# File lib/subdomain_locale/url_for.rb, line 30 def current_locale I18n.locale end
subdomain_locales()
click to toggle source
# File lib/subdomain_locale/url_for.rb, line 34 def subdomain_locales SubdomainLocale.mapping end