I am using js-routes gem ( https://github.com/railsware/js-routes ) with Rails 4.0.0.
What I want to do is include the current locale string in every route created by js routes in my rails application. And this locale string (for example, "en") will be pulled from the query string for the current query. (Thus, it can change from load of one page to another if the user decides to switch locales.)
In application_controller.rb I have the following to send and receive the locale. This successfully adds the locale parameter to the routes generated by Rails, but not via js routes. (Nothing set in config / routes.rb)
application_controller.rb:
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
def default_url_options(options={})
{ locale: I18n.locale }
end
javascript Routes.login_path(), /login, /login?locale=en, login_path(). .
, js- 'locale' , , . /login?locale=fr, - .