首页 > 解决方案 > Rails 5 - 如何防止 Rails 将语言环境添加到构造路径上的 URL?

问题描述

升级到 Rails 5.2 后,(编辑:使用)当我使用从(如)构造的路径时,"5.2.0.rc1"我现在已被添加到我的 url。如何阻止 Rails 将语言环境添加到我的 url?我永远不需要它们。?locale=enpath_helperlogin_path

我的控制器:

``` #home_controller.rb

def index
    redirect_to login_path
end

```

应用程序.rb

```

require_relative 'boot'

require 'rails/all'

Bundler.require(*Rails.groups)

module MyApp
  class Application < Rails::Application
    config.assets.initialize_on_precompile = false

    config.generators do |g|
       g.fixture_replacement :rspec
       g.fixture_replacement :factory_bot
    end
  end
end

```

怎么了:

它把我重定向到localhost:3000/login?locale=en

标签: ruby-on-railsruby-on-rails-5

解决方案


似乎在 Rails 5 中的某个地方,path_helper在构建 URL 时不再省略可选参数,如 locale。唯一要做的就是等待 PR 修复它。看起来已经做了很多,但不清楚它们是否已合并或修复是否存在于5.2.1

https://github.com/rails/rails/pull/32526

https://github.com/rails/rails/pull/32382

https://github.com/rails/rails/pull/33846


推荐阅读