Answer the question
In order to leave comments, you need to log in
How to set default variable for url in rails
There is a need to pass the current language to each url. I found the default_url_options method in the docs, but it doesn't work. Rails version 4.1.
Tried like this in the controller:
helper_method :url_for
def default_url_options
{ locale: "en" }
end
Rails.application.routes.default_url_options[:locale]= 'en'
config.action_controller.default_url_options = {:locale => "en"}
Answer the question
In order to leave comments, you need to log in
Is it registered somewhere in the marches?
Approximately like this
get '/posts(/:locale)'
# или
scope "/:locale" do
...
I actually found the problem myself. The fact is that all my routes were wrapped with a scope of the form:
scope "(:locale)", :defaults => {:locale => "ru"}, :locale => /(ru|en)/ do
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question