私はrailscastガイドに従っていますが、何らかの理由でリンクをクリックすると、paramsロケールが持ち越されていません。I18n navbarリンクのデフォルト設定を英語に戻す
は、ここで私は私のアプリとrailscastsの主な違いは、私はapplication.html.erbテンプレート上でそれをやっていると思い、私のroutes.db
Rails.application.routes.draw do
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
get 'welcome/index'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'welcome#index'
resources :foods
resources :shops
resources :communities
resources :events
resources :pictures
resources :videos
resources :services
end
get '*path', to: redirect("/#{I18n.default_locale}/%{path}")
get '', to: redirect("/#{I18n.default_locale}/")
です。だから私はそれがそれに影響しているのだろうかと思う。
ありがとうございました!
EDIT:
アプリケーションコントローラ
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :set_locale
private
def set_locale
I18n.locale = params[:locale] if params[:locale].present?
end
def default_url_options(options = {})
{locale: I18n.locale}
end
end
EDIT:
<li><a href="/foods"><i class="fa fa-cutlery" aria-hidden="true"></i> <%= t('layouts.application.food') %><span class="sr-only">(current)</span></a></li>
「ロケールを継承しない」正確な 'link_tag'を表示できますか?私の推測では、 'blah_path(locale::es)'の代わりに、あなたのurlヘルパーメソッド、e..g 'blah_path'に渡していないと思います。 –
@JanBussieck私はリンクタグを追加しました。ありがとう。 –
さて、私の答えを見てみましょう。 urlやroute helpersを 'link_to" Foods "、foods_path'のように使用してください。あなたの場合、あなたはurl paramとしてロケールを渡していません。 –