ruby-on-railsoauth-2.0ruby-on-rails-5doorkeeperbcrypt-ruby

undefined method `helper_method' for ApplicationController, Rails 5


I'm trying to integrate oAuth2.0 In my rails-api only application, using doorkeeper. But I keep getting this error, "undefined method `helper_method' for ApplicationController" and yet could not find a clear solution on how to solve it. bellow is my application_controller.rb class, Which has the helper_method. I'm following tutorial on the link below, Any help will be appreciated.

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

Solution

  • While Andy Gauge's answer is correct; the fix is incorrect. If you want to include the Helpers module while still keeping your applications as "rails-api" then simply include the module

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