Question

I'm upgrading doorkeeper to 6.7 and I have a problem with use_doorkeeper:

I followed the migration instructions and did the following:

my routes before the upgrade:

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

my routes after the upgrade:

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

Now I get an error from this line (and others) in my view:

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

Routing Error

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

It seems that doorkeeper application is getting into the locale param.

Any idea?

Was it helpful?

Solution

If you've followed the rails guides, you'll have something like the following in your 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

But your doorkeeper controllers don't inherit from your ApplicationController. So if I were you I'd pull that out into a concern

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

Then you can include this in your own ApplicationController in the normal way. For adding it to doorkeeper, there's a lot of options, but one thing you could do is add the following to config/application.rb

config.to_prepare do
  Doorkeeper::ApplicationController.send :include, LocaleConcern
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top