ahoy
ahoy copied to clipboard
Ability to specify parent controller
We try using Ahoy with a React.js application and need to add custom token authentication to controllers. The gem inherits from the ApplicationsController which isn't used in our application for the API and doesn't allow us to apply token-based authentication.
As a workaround I've reopened the base controller and included some of the required concerns:
class Ahoy::BaseController < ApplicationController
include APIExceptions
include APITokenAuth
end
But in our case, it doesn't seem right to me that it inherits from the ApplicationsController.
Which breaks the app and BaseController from the gem is never loaded. Should be required explicitly in the gem.
Thus my final BaseController looks like this:
class Ahoy::BaseController < API::APIController
private
def ahoy
@ahoy ||= Ahoy::Tracker.new(controller: self, api: true)
end
end
Hey @heaven, thanks for the suggestion. There could probably be a parent_controller option similar to Devise if you'd like to submit a PR.
@ankane this sounds like a good option. I'll try preparing a pull request, perhaps over the weekend.
Hi @ankane, on a similar note, would you also entertain a PR to to move https://github.com/ankane/ahoy/blob/master/app/controllers/ahoy/base_controller.rb#L8-L33 into a mixin?
I have a use case where I want to define behavior for a specific namespace. For now, I'm just going to copy & paste the above code into my controller, but I would like to avoid the duplication.
Thanks!
Hi @ankane, any progress with PR? Thanks.
@ankane, @heaven is it okay if take on this PR?