0
我有這個方法在我的應用程序控制器:如何在application_controller中調用方法?
before_action :set_locale
def set_locale
locale = params[:locale].to_s.strip.to_sym
I18n.locale = I18n.available_locales.include?(locale) ?
locale :
I18n.default_locale
end
def set_locale_or_redirect
unless no_locale_needed?
if params[:locale].present?
@current_locale = I18n.locale = params[:locale]
else
redirect_to locale: 'fr'
end
end
end
我想要做的是把一個鏈接在layouts/mylayout.html.erb
(我有我的導航菜單也在場)指向當前的URL,但在設定區域params並致電set_locale
。
我該怎麼做?
遺憾的是沒有。這產生的網址'http:// localhost:3000/fr/bla/foo/bar?locale = eng'我有地區「fr」在url中,而不是''之後? ' – thiebo
@thiebo你可以發佈此行動的路線嗎? 'params'通常在'?'後面或後面的動作中 – Ruslan