Reputation: 791
I've just upgraded my app to Rails 5.1 and I've been bitten by the new behaviour of skip_before_action callbacks. i.e. if callback is not defined at the time I try to skip it, it raises an error.
I know that I can pass raise: false like
skip_before_action :authorise, raise: false
But wondering if there's a better way to do it.
My main problem is that with eager load set to true, the new behaviour messes up with modular setup of my controllers.
Basically I've got dir app/controllers/api
with module_controller.rb
:
module Api
class ModuleController < ActionController::Base
before_action :authorise
end
end
Then I've got app_chats_controller.rb
which skips the authorise callback:
module Api
class AppChatsController < ModuleController
skip_before_action :authorise
end
end
With eager load, app_chats_controller.rb
gets loaded first, which means callback is not yet defined and without raise: true
error is raised.
If I have to bite the bullet and add raise: false
to everything, so be it, but surely there's a better way...
Upvotes: 3
Views: 1507
Reputation: 6138
Try adding require 'module_controller'
to the top of app_chats_controller.rb
Upvotes: 2