2017-05-15 10 views
2

더 이상 해결하고 싶지는 않지만 이상하게 생각하는 이상한 오류가 발생했습니다.영어 로케일 사용시 이상한 path_helper 오류

최근 홈페이지의 영어 버전을 추가 할 때, 나는 독일 로케일처럼 내가하는 Pathes를 생성 할 수 있다는 것을 발견 : 내가 말했듯이, 나는 것을 해결할 수 있었다

2.3.0 :023 > I18n.available_locales 
=> [:de, :en] 

2.3.0 :019 > apps_path(locale: :de) 
=> "/de/apps" 

2.3.0 :020 > apps_path(locale: :en) 
ActionController::UrlGenerationError: No route matches 
{:action=>"apps", :controller=>"pages", :locale=>:en} missing required keys: [:locale] 

url_for 또는 - 우리 예제의 경우 apps_en_path을 사용할 때.

하지만이 이상한 문제의 원인을 알고 싶습니다.

편집

git bisect 세션은 내 프로젝트에 route-translater gem를 추가하기 때문에 이런 것을 알아 내게 도움이되었다. 이 문제 외에 우리를 위해 잘 작동합니다.

# RouteTranslator.config 
config.force_locale = true 
config.locale_param_key = :locale 

routes.rb :

나는 (development.rb에서)이 설정을했다

localized 블록을 제외하고 나에게 매우 의심스러운 아무것도 없다
require_relative "#{Rails.root}/app/route_constraints/can_access_devops" 

Rails.application.routes.draw do 
    get 'health', to: 'health#show' 

    # Redirect requests with trailing 'null' 
    get '/*path/null', to: redirect('/%{path}') 

    namespace :admin do 
    root to: redirect('/admin/magazine_articles') 

    resources :jobs 
    resources :users 
    resources :magazine_categories 
    resources :magazine_articles 
    resources :media_assets 
    resources :advertisements do 
     member do 
     get 'preview' 
     end 
    end 

    namespace :devops do 
     authenticate :user do 
     constraints CanAccessDevOps do 
      mount PgHero::Engine, at: '/pghero' 
     end 
     end 
    end 
    end 

    scope '/:locale', locale: /#{I18n.available_locales.join("|")}/ do 
    root to: 'pages#home' 

    localized do 
     devise_for :users, controllers: { sessions: 'sessions' } 

     # redirect terms of use to cockpit; this is required because 
     # the packaging has a link that should point to cockpit 
     get 'home',  to: 'pages#home' 
     get 'imprint',  to: 'pages#imprint', as: 'imprint' 
     get 'lottery',  to: 'pages#lottery', as: 'lottery' 
     get 'privacy',  to: 'pages#privacy', as: 'privacy' 
     get 'terms',  to: 'pages#terms', as: 'terms' 
     get 'faq',   to: 'pages#faq',  as: 'faq' 
     get 'declaration-of-conformity', to: 'pages#declaration_of_conformity', as: 'declaration_of_conformity' 

     # Contact Page/Support Cases 
     resource :support_cases, only: [:create, :new], path_names: { new: 'new_support_case' } do 
     get :success, on: :collection 
     end 

     # redirect using the url helper to respect route localization. ugly but it works 
     get 'kontakt', to: redirect { |_, _| Rails.application.routes.url_helpers.new_support_cases_path } 

     # Workshop 
     get 'workshop', to: 'pages#workshop', as: 'workshop' 
     get 'autofit', to: 'pages#autofit', as: 'autofit' 

     # App-related 
     get 'app',  to: 'pages#app',  as: 'app' 
     get 'apps', to: 'pages#apps', as: 'apps' 
     get 'cars', to: 'pages#cars', as: 'cars' 
     get 'roadmap', to: 'pages#roadmap', as: 'roadmap' 

     # Press Material 
     get 'press',   to: 'press_materials#index',  as: 'press_materials' 
     get 'press/brand',  to: 'press_materials#brand',  as: 'press_materials_brand' 
     get 'press/team',  to: 'press_materials#team',  as: 'press_materials_team' 
     get 'press/app',  to: 'press_materials#app',  as: 'press_materials_app' 
     get 'press/pace-link', to: 'press_materials#pace_link', as: 'press_materials_pace_link' 
     get 'press/graphics', to: 'press_materials#graphics', as: 'press_materials_graphics' 

     # Feature pages 
     get 'features/automatic-emergency-call', to: 'features#ecall',    as: 'ecall' 
     get 'features/fuel-saving-trainer',  to: 'features#fuel_saving_trainer', as: 'fuel_saving_trainer' 
     get 'features/trouble-code-analysis',  to: 'features#trouble_code_analysis', as: 'trouble_code_analysis' 
     get 'features/find-my-car',    to: 'features#find_my_car',   as: 'find_my_car' 
     get 'features/logbook',     to: 'features#logbook',    as: 'logbook' 
     # old route – preserved as there might be old links somewhere pointing at this 
     get 'features/automatisches-fahrtenbuch', to: 'features#automatic_logbook' 
     # actual route: find-the-cheapest-gas-station 
     get 'features/gas-station-finder',  to: 'features#gas_station_finder', as: 'gas_station_finder' 
     get 'features/fuel-cost-tracking',  to: 'features#fuel_cost_tracking', as: 'fuel_cost_tracking' 
     get 'features/performance-monitor',  to: 'features#performance_monitor', as: 'performance_monitor' 
     get 'features/traffic-monitor',   to: 'features#traffic_monitor',  as: 'traffic_monitor' 

     # Endpoints for car finder 
     get 'cars/query', to: 'cars#identify' 
     get 'cars/:id', to: 'cars#show' 

     # Job adverts 
     get 'jobs',  to: 'jobs#index', as: 'jobs' 
     get 'jobs/:slug', to: 'jobs#show',  as: 'job' 

     # Newsletter related routes 
     post 'newsletter-sign-up',    to: 'subscribers#newsletter_create', as: 'newsletter' 
     get 'newsletter-confirmation(/:list)', to: 'subscribers#newsletter_after_confirm' 
    end 

    # Routes that we want to have under the german locale, but without translated route go here: 

    # Magazine 
    scope 'magazin' do 
     get '', to: 'magazine#index', as: 'magazine', constraints: { locale: 'de' } 

    # Redirect path without locale to locale equivalent path 
    get '/*path', to: redirect("/#{I18n.locale}/%{path}"), 
       constraints: lambda { |req| 
        !req.path.match(%r{^\/(404|422|500)$}) && 
        !req.path.match(%r{^\/(#{I18n.available_locales.join("|")})\/.*}) 
       } 

    # Redirect root to detected locale 
    root to: 'application#redirect_to_localized_root', as: :redirected_root 
end 
+0

경로 파일을 게시/링크 해주실 수 있습니까? 그것이 없으면 무엇이 문제를 일으키는 지 짐작하기가 꽤 어렵습니다. – basiszwo

+0

예, 물론 가능합니다. – Flip

+0

route_translator의 이니셜 라이저/사용자 정의 설정을 설정 하시겠습니까? – ximes

답변

2

나는 당신의 경로를 통해 빠른 플레이를했고, 나는 루트와 비슷한 문제가 있었다. 제 생각에 apps_path 경로는 기본 로케일을 (를) 매개 변수로 허용합니다. 추가 다음 option

나를 위해 그것을 해결 : 당신이 apps_path에 여러 로케일을 통과 할 수 있도록

RouteTranslator.config do |config| 
    config.generate_unlocalized_routes = true 
end 

이 올바르게 지역화되지 않은 경로를 생성합니다.

+0

우수 !! 이거 야. 그런데 왜'apps_path'가 현지화되지 않았다고 생각합니까? 'localized' 블록 안에 있습니다. – Flip

+1

글쎄, 거기에 있지만, 당신의 로케일과 똑같은 이름의 루트를 생성하는 것 같습니다 (예 : apps_en_path, apps_de_path). _apps \ _path (locale : : en) _ 어떤 이유로 든 ('rake routes'에 나열되어 있지 않지만) 사용할 수 있지만 기본 로케일에서만 작동합니다. 그 때문에 보석에 의해 생성 된 경로에서 '누락'된 것으로 의심되었습니다. – ximes

+0

이제 다시 받으겠습니다. – Flip

1

. 어떤 보석에서 나온 거니? 그렇다면 apps_path(locale: 'en') 요청이 localized 블록 외부에서 작동합니까?

콘솔에서 Rails.application.routes.url_helpers.app_path(locale: :en)을 사용하여 라우트 파일을 조정 한 후이를 테스트 할 수 있습니다.