ruby - 仅当在 ruby 中使用 i18n api 时,如何将我的 www.example.com/en 设置为 www.example.com?
问题描述
我有一个下拉菜单,其中包含选项 1. 英语 2. 泰语 但我想要类似当我选择英语时应该选择默认 url 并使用 i18n ruby 删除 en 参数。任何帮助表示赞赏。谢谢!
这是我的代码
this is my application_controller.rb file
private
def default_url_options
{ locale: I18n.locale }
end
def set_locale
I18n.locale = extract_locale || I18n.default_locale
end
def extract_locale
parsed_locale = params[:locale]
I18n.available_locales.map(&:to_s).include?(parsed_locale) ? parsed_locale.to_sym : nil
end```
This is my route.rb file
scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
get 'careers' => 'pages#careers', :as => :careers
end
解决方案
推荐阅读
- reactjs - `getInitialProps` 在页面刷新时不起作用
- python-3.x - InstaPy:知道为什么 interact_by_URL 不评论提供的 URL 吗?
- python - 了解 TensorFlow 对象检测 API 评估指标
- jquery - 剑道多选对焦
- php - 使用下拉菜单分期显示产品价格
- unity3d - 为什么我添加 ARCore 支持时没有 ARCore?
- flutter - 更新到 3.0.0 后颤振条形码扫描错误
- c++ - 如何在 Qt 中制作一个在运行时同时打开 2 个窗口的程序?
- azure-cosmosdb - 在遍历中包含来自父顶点的特定边
- c# - 在现有的网络核心应用程序中使用托管服务