Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks) with cache_classes = true Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks) with cache_classes = true ruby-on-rails ruby-on-rails

Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks) with cache_classes = true


For anyone hitting the same wall to read, the solution to this is to strictly respect Rails autoloading rules. That is

  1. Removing all the require / require_relative
  2. Add needed paths to Rails autoload paths
  3. Put files at the right places with the right names so Rails can infer where to look for code to load.

More info here: https://github.com/rails/rails/issues/15767


It's also possible that you have two concerns with same name.

In my case I faced this error while running rails swagger:docs SD_LOG_LEVEL=1 .

$ rails swagger:docs SD_LOG_LEVEL=1Cannot define multiple 'included' blocks for a Concern1.0: 19 processed / 49 skipped

Since I had two swagger files with same name.

module SwaggerDocs::TrackerPhases  extend ActiveSupport::Concern  included do  endendmodule SwaggerDocs::TrackerPhases  extend ActiveSupport::Concern  included do  endend

I renamed second file as:

module SwaggerDocs::ClientTrackerPhases  extend ActiveSupport::Concern  included do  endend