ApplicationController 的未定义方法“helper_method”,Rails 5

2024-05-14

我正在尝试使用doorkeeper 将oAuth2.0 集成到我的仅rails-api 应用程序中。但我不断收到此错误“ApplicationController 的未定义方法‘helper_method’”,但无法找到解决该问题的明确解决方案。下面是我的 application_controller.rb 类,其中有 helper_method 。我正在关注下面链接上的教程,任何帮助将不胜感激。

https://www.sitepoint.com/getting-started-with-doorkeeper-and-oauth-2-0/ https://www.sitepoint.com/getting-started-with-doorkeeper-and-oauth-2-0/

class ApplicationController < ActionController::API

private 

    def current_user
        @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end

    helper_method :current_user

end

虽然 Andy Gauge 的答案是正确的;修复不正确。如果您想包含 Helpers 模块,同时仍将应用程序保留为“rails-api”,那么只需包含该模块即可

class ApplicationController < ActionController::API
  include ActionController::Helpers
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ApplicationController 的未定义方法“helper_method”,Rails 5 的相关文章

随机推荐