How to setup maintenance tasks with a custom controller? #646
-
Hi! I want to try out maintenance tasks, but before I proceed, I need to know how to overwrite the controller provided by the engine. I'd like to add authorization to only allow admins to access the maintenance page. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
One thing that can be done is to wrap the route in a constraint, like it's usually done with Sidekiq for example: https://github.com/mperham/sidekiq/wiki/Monitoring#authentication You can also directly access # config/initializers/maintenance_tasks.rb
Rails.application.config.to_prepare do
MaintenanceTasks::ApplicationController.class_eval do
include Authentication
before_action :authenticate
end
end |
Beta Was this translation helpful? Give feedback.
-
I tested with a custom constraint class, and it works really well! Thanks for the help 🧡 |
Beta Was this translation helpful? Give feedback.
One thing that can be done is to wrap the route in a constraint, like it's usually done with Sidekiq for example: https://github.com/mperham/sidekiq/wiki/Monitoring#authentication
You can also directly access
MaintenanceTasks::ApplicationController
and use abefore_action
there if you want, e.g.: