Skip_before_action callbacks in Rails 5.1 and inheritance

I just upgraded my application to Rails 5.1 and I was bitten by the new skip_before_action callback behavior. that is, if the callback is not defined at the time I try to skip it, it throws an error.

I know I can pass the raise: false like

skip_before_action :authorise, raise: false

      

But I wonder if there is a better way to do this.

My main problem is that when high load is set to true, the new behavior is due to the modularity of my controllers.

Basically I have a dir app/controllers/api

with module_controller.rb

:

module Api
  class ModuleController < ActionController::Base
    before_action :authorise
  end
end

      

Then I have app_chats_controller.rb

one that skips the callback authorization:

module Api
  class AppChatsController < ModuleController
    skip_before_action :authorise
  end
end

      

High load is loaded first app_chats_controller.rb

, which means the callback is not yet defined and no error is thrown raise: true

.

If I need to bite a bullet and add raise: false

to everything, so be it, but of course the best way ...

+3


source to share


1 answer


Try adding require 'module_controller'

to the beginningapp_chats_controller.rb



+1


source







All Articles