Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

I have a certain module which is used in a Rails 4.1.1 application

module A
   extend ActiveSupport::Concern
   included do
     #Some code
   end
end

which is included in a class

class Some
  include A
end

This works great with cache_classes=true in application.rb. Now, if I turn off the caching of classes, I get Cannot define multiple 'included' blocks for a Concern (ActiveSupport::Concern::MultipleIncludedBlocks) exception upson starting the server.

How should one deal with such an issue since reloading the classes is done by Rails?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...