uninitialized constant Api::Doorkeeper

938 Views Asked by At

I have API engine inside my Rails app and I've mounted the engine under in the main app routes

Rails.application.routes.draw do
  mount Api::Engine => "/api"
end

and I want to add the doorkeeper routes using use_doorkeeper function in my routes like this

Api::Engine.routes.draw do
  use_doorkeeper :scope => "api/oauth"
end

this doesn't work because it tries to find controllers under api/doorkeeper/controller_name instead of doorkeeper/controller_name

as a workaround I've added doorkeeper routes in main app routes.rb with a scope like this

Rails.application.routes.draw do
  mount Api::Engine => "/api"
  use_doorkeeper :scope => "api/oauth"
end

But I want to know if there is a solution so I can still add the routes to api/config/routes.rb and make reference the correct controllers path

1

There are 1 best solutions below

0
On BEST ANSWER

my colleague suggested this solution found here and it worked for me :)

MyEngine::Engine.routes.draw do
  old_scope = @scope[:module]
  @scope[:module] = nil
  use_doorkeeper
  @scope[:module] = old_scope
end