Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 可以在Rails中本地化静态页面URL吗?_Ruby On Rails_Ruby On Rails 4_Routing_Url Routing - Fatal编程技术网

Ruby on rails 可以在Rails中本地化静态页面URL吗?

Ruby on rails 可以在Rails中本地化静态页面URL吗?,ruby-on-rails,ruby-on-rails-4,routing,url-routing,Ruby On Rails,Ruby On Rails 4,Routing,Url Routing,我最近更新了Rails 4.0.4应用程序的routes.rb文件,以便能够正确处理多个本地化。它看起来像这样: scope ':locale', locale: /#{I18n.available_locales.join("|")}/ do # All the routing happens here # ... root "home#index", as: :locale_root match '*path', to: "locale#not_found", via: :

我最近更新了Rails 4.0.4应用程序的
routes.rb
文件,以便能够正确处理多个本地化。它看起来像这样:

scope ':locale', locale: /#{I18n.available_locales.join("|")}/ do
  # All the routing happens here
  # ...

  root "home#index", as: :locale_root
  match '*path', to: "locale#not_found", via: :all
end

# handles /
root to: redirect("/#{I18n.default_locale}")
match '*path', to: redirect(status: 307) {|params| "/#{I18n.default_locale}/#{params[:path]}"}, via: :all
match '', to: redirect("/#{I18n.default_locale}"), via: :all
我想路由静态页面能够根据当前URL更改URL。假设我有一个通过
http://mydomain/how_it_works
。使用多个本地化,我希望得到:

http://mydomain/en/how_it_works  # English
http://mydomain/it/come_funziona # Italian
路由器应链接到相同的
控制器#操作
,更改显示的URL。 我还没有找到一个gem或合适的解决方案来实现这一点,所以我想知道Rails是否能够本地化这种静态URL


此外,我希望能够在视图中使用相同的
*\u路径
helper来处理这些URL,“忽略”当前区域设置。锿。如果我使用
它是如何工作的\u path
并且区域设置是
:en
我得到
http://mydomain/en/how_it_works
,否则,如果区域设置为
:它
我得到
http://mydomain/it/come_funziona

我知道两年前有人问过这个问题,但也许这能帮助像我这样现在面临这个问题的人

我的问题与此非常相似,我最终在Rails 5应用程序中使用了以下gem: