Ruby on rails 未定义的方法“helper”方法';对于ApplicationController,Rails 5

Ruby on rails 未定义的方法“helper”方法';对于ApplicationController,Rails 5,ruby-on-rails,oauth-2.0,ruby-on-rails-5,doorkeeper,bcrypt-ruby,Ruby On Rails,Oauth 2.0,Ruby On Rails 5,Doorkeeper,Bcrypt Ruby,我正在尝试使用doorkeeper将oAuth2.0集成到我的rails api专用应用程序中。但我一直遇到这个错误,“ApplicationController的未定义方法'helper_method',但却找不到一个明确的解决方案。下面是我的应用程序\u controller.rb类,它有helper\u方法。我在下面的链接上跟随教程,任何帮助都将不胜感激 class ApplicationController

我正在尝试使用doorkeeper将oAuth2.0集成到我的rails api专用应用程序中。但我一直遇到这个错误,“ApplicationController的未定义方法'helper_method',但却找不到一个明确的解决方案。下面是我的应用程序\u controller.rb类,它有helper\u方法。我在下面的链接上跟随教程,任何帮助都将不胜感激

class ApplicationController
因为API没有视图,所以
helper\u方法
方法已被删除。如果要将
当前用户
方法添加到视图中,请改用ActionController::Base

您可以在这里看到,模块集合中不包括AbstractController::Helpers

在本文所基于的Rails 4中,该方法包含在ActionController::Helpers中。如图所示

解决方法:

#application_controller.rb
class ApplicationController < ActionController::Base
#应用程序_controller.rb
类ApplicationController
而安迪·盖特的答案是正确的;修正不正确。如果您希望包含Helpers模块,同时仍将应用程序保持为“railsapi”,那么只需包含该模块即可

class ApplicationController < ActionController::API
  include ActionController::Helpers
end
class ApplicationController
class ApplicationController < ActionController::API
  include ActionController::Helpers
end