I am writing an authentication engine that has an authenticate! method in its application controller along with a current user helper method etc.
I would like to be able to call this authenticate! method inside my main application and have it use the current_user that is set by the engines application controller.
After doing a little bit of googling, I ran across this post How to access Rails Engines methods from main application? but that wasn't helpful and neither were any of the suggested links within.
Right now inside my engine.rb file I have the following code:
require 'my_engine'
module MyEngine
class Engine < ::Rails::Engine
isolate_namespace MyEngine
initializer "my_engine.load_helpers" do
ActiveSupport.on_load(:action_controller) do
include MyEngine::Helpers
end
end
end
end
But this gives me the following error
uninitialized constant MyEngine::Helpers
What would be the best way to go about getting this done if it is possible?
Before starting this, the way I had things done was to set a session[:current_user_id] which I then passed to a current_user method in the main controller which also housed the authenticate! method that sent the user to the authentication engine. It would be nice if I can just call authenticate! in the main application and have the engines application controller handle that method and set the current user.