0

我看到了一个“railscasts”演员表,并没有像他们告诉我的那样。这是我的 route.rb 的一部分

  scope ':locale', :locale=> /#{I18n.available_locales.join("|")}/ do
    #..........
    #..........
    namespace :admin do
      resources :products do
         get :who_bought, :on=>:member
     end
     end
  end

  match '*path', :to=> redirect("/#{I18n.default_locale}/%{path}")
  match '', :to=> redirect("/#{I18n.default_locale}")

因此,现在引起了一些问题。看我的日志。

Started GET "/products/4/who_bought.atom" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/en/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/en/en/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/en/en/en/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/en/en/en/en/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400
2012-08-31 09:58:35 INFO -- 

Started GET "/en/en/en/en/en/en/en/products/4/who_bought" for 127.0.0.1 at 2012-08-31 09:58:35 +0400 

或者

Started GET "/assets/logo.png" for 127.0.0.1 at 2012-08-31 10:55:36 +0400
2012-08-31 10:55:36 INFO -- Served asset /logo.png - 404 Not Found (13ms)
2012-08-31 10:55:36 INFO -- 

Started GET "/assets/products/tea1.jpg" for 127.0.0.1 at 2012-08-31 10:55:36 +0400
2012-08-31 10:55:36 INFO -- Served asset /products/tea1.jpg - 404 Not Found (2ms)
2012-08-31 10:55:38 INFO -- 

Started GET "/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/en/en/assets/products/tea1" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

Started GET "/en/en/en/en/en/en/en/en/assets/logo" for 127.0.0.1 at 2012-08-31 10:55:38 +0400
2012-08-31 10:55:38 INFO -- 

如果我去"http://localhost:3000/en/fdsfdsfdsfds"它会将我重定向到"http://localhost:3000/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/en/fdsfdsfdsfds"

我想摆脱它。我该怎么办?

4

2 回答 2

0

问题出在您的路线文件上(假设您没有重定向到其他地方)。尝试将最后一位更改为:

root to: redirect("/#{I18n.default_locale}") 
match '*path', :to => redirect("/#{I18n.default_locale}/%{path}")

也许删除其他地方的电话

puts "INFO...

这使您的日志变得混乱。

于 2012-08-31T07:20:34.383 回答
0

问题是您没有处理对无效资源的范围请求。您的应用程序通过向其添加区域设置来重定向请求,但如果在区域设置块中没有与它匹配的内容,则它会继续向下并到达matchcatch-all 行,将另一个区域设置附加到它,无穷无尽。

声明资源后,您需要在范围块添加另一条全能行,如下所示:

scope ':locale', :locale=> /#{I18n.available_locales.join("|")}/ do

  ...

  namespace :admin do
    resources :products do
      get :who_bought, :on=>:member
   end
  end

  root to: "locale#root"
  match "*path", to: "locale#not_found"
end

match '*path', :to=> redirect("/#{I18n.default_locale}/%{path}")
match '', :to=> redirect("/#{I18n.default_locale}")

在您提供的情况下,请求 URL 与任何资源都不匹配,因为您已将资源命名为 下admin,因此您需要在具有前缀等的 URL 上访问/en/admin/它们/es/admin/

另请参阅:为什么 Rails 应用程序意外重定向而不是匹配路由?

于 2012-08-31T07:21:01.420 回答