title: ActiveSupport::Concern and extending mongoid model
body: <p>I am using mongoid with rails 3 and have come lately to a very tough
  problem and I need an advice.</p>
  
  <p>I am working on a CMS and one of the ideas was that CMS would provide
  some basic models definitions and end user would, if needed, extend
  basic class with its own definitions and controls and save them in different collections (tables).</p>
  
  <pre><code>class DcPage
    include Mongoid::Document
  
    field a ....
    belongs_to b ....
    validates a ....
  end
  
  class MyPage &lt; DcPage
    field c ....
    validates c ....
  end
  </code></pre>
  
  <p>Up until last version of mongoid this worked (with little hack) and data
  would be saved to my_pages collection. Because of some problem, mongoid no
  longer support this behaviour and data always gets saved to dc_pages
  collection.</p>
  
  <p>When explaining my problem, mongoid team suggested that I use
  ActiveSupport::Concern and provided me with an example. Which works
  perfectly OK if extended class is defined in same source file. Which
  btw. never happens in praxis.</p>
  
  <pre><code>module CommonBehaviour
    extend ActiveSupport::Concern
  
    included do
      field :subject, type: String, default: ''
      # ...
    end
  end
  
  class DcPage
    include Mongoid::Document
    include CommonBehaviour
  end
  
  class MyPage
    include Mongoid::Document
    include CommonBehaviour
  end
  </code></pre>
  
  <p>So far I have found out that it works if I require basic source file in
  my second file. Which looks like this:
  require '/some/path/to/my/gem/app/models/dc_page.rb</p>
  
  <p>Can you can see my pain now. Basic source file would of course be backed into
  gem and therefor becomes a moving target.</p>
  
  <p>Please help me with better solution.</p>
  
  <p>by
  TheR</p>