【发布时间】:2015-02-03 20:41:16
【问题描述】:
我正在开发一个多语言的 Rails 应用程序,我需要为每个区域设置不同的路线。对我来说很难这样解释,所以我举个例子:
- zh:/zh/定价
- es: /es/precios
我找到了这个答案:Rails 4 i18n, how to translate routes where subdomain is used for the locale
因此我的 routes.rb 看起来像这样:
scope "/:locale" do
get "/", to: "pages#index", as: "index"
get "/#{I18n.t("pricing")}", :to => "pages#pricing", :as => "pricing"
end
我还在应用程序加载(应用程序控制器 before_action)上使用 AppName::Application.reload_routes!,但就在区域设置更改之后 /locale 保持不变后的其余 URI - 当用户尝试重新加载页面时会出现问题,因为那已经不存在了。其他点击没问题,使用新的区域设置 URI。
我正在考虑一个系统来确定我当前的 URI 是否正确,如果不是,则将其重定向到那里,但我认为这是次优的。你有什么建议吗?
提前谢谢你。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 routes rails-i18n