weppos / breadcrumbs_on_rails

A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
https://simonecarletti.com/code/breadcrumbs-on-rails
MIT License
944 stars 188 forks source link

Dynamic switching languages only changes last element #115

Closed PragmaticEd closed 6 years ago

PragmaticEd commented 6 years ago

If using provided example:

class ApplicationController < ActionController::Base
  before_action :set_locale

  private

  def set_locale
    I18n.locale = (params[:locale] || I18n.locale) # simplified for example
  end
end

class Admin::ApplicationController < ApplicationController
  add_breadcrumb I18n.t("breadcrumbs.admin"), admin_path
end

class Admin::UsersController < Admin::ApplicationController
  add_breadcrumb I18n.t("breadcrumbs.admin_users"), admin_users_path
end

And we go to /admin/users?locale=en

it loads perfectly: Admin / Users

But if we switch language and refresh the page: /admin/users?locale=lv

I get Admin / Lietotāji, when it should be Administrācija / Lietotāji, meaning, it only translates the last item.

To get the all breadcrumbs to update, u have to go to first link, admin_path in this case, and then click to the last one, admin_users_path, in this example.

Any ideas how to fix this?

weppos commented 6 years ago

You need to use the instance-level add_breadcrumb, otherwise the value is cached at class level.

I encourage you to use https://stackoverflow.com/ for support.

PragmaticEd commented 6 years ago

So, basically, repeat ur self in each action of each controller..

weppos commented 6 years ago

Use a before action.

NSNJRGL commented 4 years ago

Is it solved? How to solve it?