ruby-on-rails - ApplicationController,Rails 5 的未定义方法 `helper_method'

标签 ruby-on-rails oauth-2.0 ruby-on-rails-5 doorkeeper bcrypt-ruby

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

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

关于ruby-on-rails - ApplicationController,Rails 5 的未定义方法 `helper_method',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39171741/

相关文章:

ruby-on-rails - Rails 功能测试、路由错误

angularjs - 使用 OAuth.io 实现 AngularJS 的授权和认证

spring-security - Spring OAuth : Resource Server with Authorization Server backend

python - Linkedin 401 错误通过 python

mocking - 为什么我的模拟没有在我的 minitest 测试运行中使用?

jquery - rails 5 : form remote - trigger submit

sql - 如何从 Ruby 直接将 SQL 与 MySQL 对话?

ruby-on-rails - Rubymine -- 配置远程 SDK?

ruby-on-rails-5 - 使用 protect_from_forgery 和 : :exception but redirect user to login page if session expired

ruby-on-rails - 如何以编程方式列出Rails中的所有 Controller