2017-09-12 1 views
0

, 나는 필터 전에로 로케일 처리를 강제하고 있습니다 :기본 로케일이 작동하지 않는 이유는 무엇입니까? 내 응용 프로그램 컨트롤러에서

before_filter :set_locale 

def set_locale 
    #I18n.default_locale is en 
    I18n.locale = extract_locale_from_tld || I18n.default_locale 
end 

def extract_locale_from_tld 
    parsed_locale = params[:locale] || ((lang = request.env['HTTP_ACCEPT_LANGUAGE']) && lang[/^[a-z]{2}/]) 
    #so, english is the default language. 
    parsed_locale= 'en' if parsed_locale.nil? 
    I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil 
end 

을하지만, 나는 그것이 결국 오류 404입니다 라우팅 오류로 초래 http://localhost:3000/ko/lab를 방문하려고합니다. enter image description here

어떤 조언 :

라우팅 오류로 발생합니다 다음 있는지 찾아 밖으로 어떤 로케일

?

편집

내 route.er :

# -*- encoding : utf-8 -*- 
MyApp::Application.routes.draw do 

    mount Alchemy::Engine => 'blog' 

    Rails.application.routes.draw do 
    filter :pagination, :uuid, :locale 
    end 

    devise_for :users, :controllers => { :omniauth_callbacks => "callbacks", 
             :sessions => "users/sessions", 
             :registrations => "users/registrations"} 



    resources :authentications 


    resources :experiments 
    get 'experiments/:id/info_edit' => 'experiments#info_edit',:constraints => { :id => /\d+/ } 

    get 'sitemap.xml', :to => 'sitemap#index', :defaults => {:format => 'xml'} 



    match 'lang' => 'home#set_lang', :via => [:get] 

    #match 'free_trial' => 'home#free_trial', :via => [:get] 
    match 'useful_links' => 'home#useful_links', :via => [:get] 
    match 'home' => 'home#home', :via => [:get] 


    match 'contact-us' => 'contact#new', :as => 'contact_us', :via => :get 
    match 'contact' => 'contact#create', :as => 'contact', :via => :post 

    match 'dashboard' => 'experiments#index', :via => [:get] 
    post 'notifications' => 'subscriptions#instant_payment_notification' 


    match 'users_experiments' => 'experiments#users_experiments', :via => [:get] 
    match 'hire_us' => 'home#hire_us', :via => [:get] 


    get 'lab' => 'experiments#lab' 

    get 'experiments/:id/review-edit' => 'experiments#review', :as => :review 
    get 'experiments/:id/cancel-edit' => 'experiments#cancel_edit', :as => :cancel_edit 

    get 'experiments/:id/approve-edit' => 'experiments#approve', :as => :approve 
    get 'experiments/:id/reject-edit' => 'experiments#reject', :as => :reject 


    get 'experiments/:id/profile' => 'experiments#profile', :as => :profile 



    match 'amazon' => 'experiments#amazon', :via => [:get] 


    match 'trial_account' => 'home#trial_account', :via => [:get] 
    match 'student_account' => 'home#student_account', :via => [:get] 
    match 'school_account' => 'home#school_account', :via => [:get] 



    match 'create_account' => 'home#registration_redirect', :via => [:get] 
    match 'users/create_account' => 'home#registration_entrance', :via => [:get] 
    match 'registration_redirect' => 'home#registration_redirect', :via=>[:post] 
    # You can have the root of your site routed with "root" 
    # just remember to delete public/index.html. 
    root :to => 'home#home' 

    get "/auth/oauth2/callback" => "auth0#callback" 
    get "/auth/verification_complete" => "auth0#verification_complete" 
    get "/auth/failure" => "auth0#failure" 



end 

내 서버 로그 :

Started GET "/ko/lab" for 127.0.0.1 at 2017-09-12 08:58:56 +0300 Processing by ApplicationController#routing_error as HTML
Parameters: {"path"=>"ko/lab"} User Load (202.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 12899]] Completed 404 Not Found in 205ms ko/lab excluded from capture: DSN not set

ActionController::RoutingError (ko/lab):
app/controllers/application_controller.rb:35:in routing_error'
lib/rack/seoredirect.rb:20:in
call'

+0

당신이 보여 로그를 포함 할 수 있습니다 라우팅 오류 및 routes.rb 파일? – max

답변

0

기본 로컬 작업을 수행하지만 /:locale/lab 일치하는 경로가 없습니다. 간단합니다.

scope을 사용하여 현지화 된 경로를 만들 수 있습니다. 레일스가이 작업을 수행하지 않습니다.

scope '(:locale)', locale: /#{I18n.available_locales.join('|')}/ do 
    get '/' => 'home#home' # this will map /en to home#home 
    get 'lab' => 'experiments#lab' 
    # ... 
end 

이 아마 그것의 전체 범위에 자원 도우미를 사용하여 정말 지저분한 루트 파일을 리팩토링하기에 좋은 시간이다 :

resources :experiments do 
    member do 
    get :info_edit 
    # ... 
    end 
end 

참조 http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

+0

내가 제안한 것을 시도했지만 여전히 라우팅 오류가 발생합니다. – simo

관련 문제