0

我正在将门卫升级到 6.7,但我对 use_doorkeeper 有疑问:

我按照迁移说明进行了以下操作:

我升级前的路线:

  scope "(:locale)", :locale => /.{2}/ do
    ...
    mount Doorkeeper::Engine => '/oauth', as: 'doorkeeper'
    ...
  end

我升级后的路线:

  scope "(:locale)", :locale => /.{2}/ do
    ...
    use_doorkeeper
    ...
  end

现在,在我看来,这一行(和其他行)出现错误:

<td><%= link_to application.name, [:oauth, application] %></td>

路由错误

没有路由匹配 {:action=>"show", :controller=>"doorkeeper/applications", :locale=>#< Doorkeeper::Application id: 5, name: "My App", uid: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx... ", secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...", redirect_uri: " http://www.myapp.com ", created_at: "2013-08-26 14:33:38", updated_at: "2013-08-26 14: 33:38">}

看来门卫应用程序正在进入语言环境参数。

任何想法?

4

1 回答 1

4

如果您遵循rails guides,您的ApplicationController.

before_action :set_locale

def set_locale
  I18n.locale = params[:locale] || I18n.default_locale
end

def default_url_options(options={})
  { locale: I18n.locale }
end

但是您的门卫控制器不会从您的ApplicationController. 所以如果我是你,我会把它拉出来担心

module LocaleConcern
  extend ActiveSupport::Concern

  included do
    before_action :set_locale
  end

  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end

  def default_url_options(options={})
    { locale: I18n.locale }
  end

end

然后,您可以以正常方式include自行ApplicationController处理。要将其添加到门卫,有很多选项,但您可以做的一件事是将以下内容添加到 config/application.rb

config.to_prepare do
  Doorkeeper::ApplicationController.send :include, LocaleConcern
end
于 2013-08-27T17:24:07.537 回答