Reputation: 395
I've default_url_options that set locale like that
def default_url_options
{
locale: I18n.locale,
}
end
but in one case I want to redirect_to something_url
without adding ?locale=en
currently direct_to something automatically add locale like this http://localhost/something?locale=en I want to remove the locale params
Upvotes: 0
Views: 131
Reputation: 159
In above snippet simply add,
def default_url_options
I18n.locale = (url == something_url) ? nil : I18n.default_locale
{
locale: I18n.locale
}
end
here url and something_url you need to add as per your application.
Hope this will work in your case.
Upvotes: 0
Reputation: 7024
You can prevent adding default url options by explicitly setting them to nil
in the url helper:
redirect_to something_url(locale: nil)
Upvotes: 2
Reputation: 101811
Provided that en
is the default locale you can do:
def default_url_options
{}.tap do |options|
if I18n.locale != I18n.default_locale
options[:locale] = I18n.locale
end
end
end
Upvotes: 0