I have locales defined like this:
# routes.rb
scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
...
root "home#index"
end
I also set locale in default_url_params in ApplicationController.
This way I have all my routes and urls to include locales like this: http://example.com/en/something
http://example.com/fr/something
It is an expected behavior for me.
I also have root urls like this:
http://example.com/en
http://example.com/fr
What I want to achieve is exclude en (default) locale for root_path, so that root_path for :en locale (either passed explicitly or via default_url_params) is http://example.com/
Is there any way to do it?
Can I maybe override root_path to do my hacking inside it?
Thank you.
override root_path method in your ApplicationController:
def root_path
(I18n.locale == 'en') ? '/' : super
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With