Module: SubdomainLocale::UrlFor
- Defined in:
- lib/subdomain_locale/url_for.rb
Instance Method Summary collapse
- #current_locale ⇒ Object
- #default_url_options ⇒ Object
- #subdomain_locales ⇒ Object
-
#url_for(options) ⇒ Object
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.
Instance Method Details
#current_locale ⇒ Object
28 29 30 |
# File 'lib/subdomain_locale/url_for.rb', line 28 def current_locale I18n.locale end |
#default_url_options ⇒ Object
22 23 24 25 26 |
# File 'lib/subdomain_locale/url_for.rb', line 22 def super.merge({ subdomain: subdomain_locales.subdomain_for(current_locale) }) end |
#subdomain_locales ⇒ Object
32 33 34 |
# File 'lib/subdomain_locale/url_for.rb', line 32 def subdomain_locales SubdomainLocale.mapping end |
#url_for(options) ⇒ Object
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
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/subdomain_locale/url_for.rb', line 10 def url_for() = .dup if .key?(:locale) # Locale specified, force full URL locale = .delete(:locale) [:subdomain] = subdomain_locales.subdomain_for(locale) [:only_path] = false end super end |