简体   繁体   English

如何将区域设置重定向为Rails中的参数?

[英]How do I redirect with locales as params in Rails?

Example

I have a home_path that is /de/home/ and one that is /en/home/ in my Rails app. 我有一个home_path是/ de / home /和一个在我的Rails应用程序中的/ en / home /。 How can I choose which one I want to redirect to when I have redirect_to home_path? 当我有redirect_to home_path时,如何选择要重定向到哪一个?

Basically you have to redirect user based on user's locale, for example to redirect a user you can do this in your root controller: 基本上,您必须根据用户的区域设置重定向用户,例如,重定向用户,您可以在根控制器中执行此操作:

 scope "/:locale", locale: /#{I18n.available_locales.join("|")}/ do
    root to: redirect("/%{locale}/posts", status: 302)
  end

Here is more tip and tricks about handling locals . 这里有关于处理当地人的更多提示和技巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM