Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to specify parent controller #478

Open
heaven opened this issue Mar 26, 2021 · 6 comments
Open

Ability to specify parent controller #478

heaven opened this issue Mar 26, 2021 · 6 comments

Comments

@heaven
Copy link

heaven commented Mar 26, 2021

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.

@heaven
Copy link
Author

heaven commented Mar 26, 2021

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

@ankane
Copy link
Owner

ankane commented Mar 29, 2021

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.

@heaven
Copy link
Author

heaven commented Mar 29, 2021

@ankane this sounds like a good option. I'll try preparing a pull request, perhaps over the weekend.

@kfprimm
Copy link

kfprimm commented May 21, 2021

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!

@durcak
Copy link

durcak commented Jan 4, 2022

Hi @ankane, any progress with PR? Thanks.

@jevin
Copy link

jevin commented Jan 18, 2023

@ankane, @heaven is it okay if take on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants