routes - Rails mountable engine under a dynamic scope -
say have these routes:
scope '(:locale)', :locale => /en|de/ mount users::engine => "users", as: 'users_engine' end
and in engine's view:
<%= link_to 'new user', action: :new, controller: :users, locale: :de %>
i get
/en/users/users/new?locale=de
instead of
/de/users/users/new
i have included in application controller:
def set_locale if params.include?('locale') i18n.locale = params[:locale] rails.application.routes.default_url_options[:locale] = i18n.locale end end
and works fine in main app
i have found way right url
users::engine.routes.url_for controller: 'users/users', action: :new, only_path: true, locale: :de
but think there should improve way , if making change-locale link in layout ?
<%= link_to locale: :de %>
i cannot know exact engine be
thanks vm.
i think have found solution that...
just utilize url_options-method in application_controller.rb-file (see link below)
see: http://stackoverflow.com/a/18299975/603126
hope helps!
regards
philipp
ruby-on-rails routes
No comments:
Post a Comment