Why rails app is redirecting unexpectedly instead of matching the route?

后端 未结 2 1942
臣服心动
臣服心动 2021-01-06 16:06

I asked this question earlier and thought it was fixed, but it\'s not. Previous question here

My problem is I am trying to set my routes so that when I type in

2条回答
  •  耶瑟儿~
    2021-01-06 17:11

    We meet again, ruevaughn. :)

    I created a test rails app and the following minimal example works for me:

    scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
      resources :sites do
        collection do
          get :admin
        end
      end
    
      root to: "locale#root" # handles /en/
      match "*path", to: "locale#not_found" # handles /en/fake/path/whatever
    end
    
    root to: redirect("/#{I18n.default_locale}") # handles /
    match '*path', to: redirect("/#{I18n.default_locale}/%{path}") # handles /not-a-locale/anything
    

提交回复
热议问题