ActiveSupport :: Concern and renewal of the mongoid model

I use a mangoid with rails 3 and I have come up with a very tough problem lately and I need some advice.

I am working on a CMS, and one of the ideas was that the CMS would provide some definitions of the base models and the end user, if necessary, would expand the base class with its own definitions and controls and store them in different collections (tables).

class DcPage
  include Mongoid::Document

  field a ....
  belongs_to b ....
  validates a ....
end

class MyPage < DcPage
  field c ....
  validates c ....
end

Until the latest mongoid version, this worked (with a little hack) and the data will be stored in the my_pages collection. Due to some problem, mongoid no longer supports this behavior, and data is always stored on the dc_pages collection.

, mongoid ActiveSupport:: . , . . .

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

, , . : require '/some/path/to/my/gem/app/models/dc_page.rb

. , , .

, .

Þér

+5
1

, , , . .

- , . , /.

+1

All Articles