good_job icon indicating copy to clipboard operation
good_job copied to clipboard

Allow customisation of the dashboard controller parent class

Open ollym opened this issue 2 years ago • 1 comments

Like you have:

GoodJob.active_record_parent_class = "ApplicationRecord"

Would be good to have similar for the dashboard:

GoodJob.dashboard_controller_parent_class = "ApplicationController"

Where we can control things like authentication more easily, for example we have a Admin::ApplicationController which we have all the authentication already setup as hooks.

Let me know.

ollym avatar Aug 03 '22 11:08 ollym

@ollym thanks for opening this issue. With experience, I think I regret the creation of GoodJob.active_record_parent_class = "ApplicationRecord":

  • Sorbet hates it
  • It scares me out when I have to think about autoloading, reloading and Rails initialization order.

I don't have plans to remove it, but the pattern I am thinking of more strongly recommending is configuring via an initializer. Which is less pretty, but I think more resilient from the perspective of Ruby and Rails:

# initializers/good_job.rb

ActiveSupport::Reloader.to_prepare do
  # open up the class and put your behavior in it directly:
  class GoodJob::BaseRecord # <-- probably rename this GoodJob::ApplicationRecord for consistency
    # put behavior here
  end

  class GoodJob::ApplicationController
    # put behavior here
  end
end

But I haven't made a decision. I am not sure.

bensheldon avatar Aug 05 '22 17:08 bensheldon

This was documented in #1082

bensheldon avatar Nov 27 '23 04:11 bensheldon