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
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
Because APIs don't have a view, the helper_method
method has been removed. If you want to add your current_user
method to a view, use ActionController::Base instead.
ActionController included Modules on Github. You can see here that AbstractController::Helpers is not included in the Modules collection.
In Rails 4, which the article is based, the method was included in ActionController::Helpers. As seen in the APIDock.
Workaround:
#application_controller.rb
class ApplicationController < ActionController::Base
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With