ruby-on-railsrubyrubocoplinterruby-module

How to deal with `RuboCop::Cop::Rails::LexicallyScopedActionFilter ` when including a module?


I have a class similar to this:

class UsersController  < ApplicationController
  before_action :user_authentication, except: :create

  include Crud
end

Rubocop Rails complains, "create is not explicitly defined on the class."

Create action is defined in my included module. What shall I do?


Solution

  • I'd be included to just disable the cop (either on the specific controllers that use include Crud if they're rare, or globally if they're common).

    Or alternatively, consider not using this module? How much benefit is it giving by removal of repetition vs ease of understanding/maintaining the code?

    Aside from that, the best way I can think to make rubocop happy is:

    class UsersController  < ApplicationController
      before_action :user_authentication, except: :create
    
      include Crud
    
      # The `LexicallyScopedActionFilter` cop requires this method, but it relies
      # on behaviour defined in the superclass, so needs to invoke `super`
      def create
        super
      end
    end