'Removing locale parameter from url in rails
I'm having to use rails url helpers, rather than path helpers (in some cases) as I'm working with an app that uses subdomains, so am having to pass the domain option as a parameter.
However this is causing the links to render as:
http://sub.domain.dev/the-page?locale=en
I've tried using variations of the following in the application controller, to no avail:
def default_url_options(options={})
{ :locale => :en }
end
How do I remove that locale parameter?
I'm using RefineryCMS.
Solution 1:[1]
Odd, but for anyone in my situation:
When using RefineryCMS with engine, even though locale is not being used, and other engines produce the expected urls, the fix was to set:
# config/initializers/refinery/i18n.rb
Refinery::I18n.configure do |config|
config.enabled = false
end
Solution 2:[2]
For refinerycms-i18n ~> 4.0:
# config/initializers/refinery/i18n.rb
Refinery::I18n.configure do |config|
config.url_filter_enabled = false
end
Solution 3:[3]
If you are using locale I recommend the following:
In your routes.rb:
scope "(:locale)", locale: /en|br/ do
resources :the-pages
end
In your application controller:
before_filter :set_locale
def set_locale
I18n.locale = params[:locale]
end
def default_url_options(options={})
{ locale: I18n.locale }
end
In this way, your urls will become:
http://sub.domain.dev/en/the-page
http://sub.domain.dev/pt/the-page
EDIT - if you don't want any locale, you need to remove it from your application controller:
#remove the below
def default_url_options(options={})
{ :locale => :en }
end
Also, make sure you don't have any locale in your routes.rb
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chris Edwards |
Solution 2 | Papershine |
Solution 3 |