Damjan Rems
2013-Apr-26 20:41 UTC
Question about ActiveSupport::Concern and mongoid model definition
I am using mongoid and MongoDB and have come lately to a very tough problem and I need an advice. 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 extension and save them to different collection (table). class DcPage include Mongoid::Document field a .... belongs_to b .... validates a .... end class MyPage < DcPage field c .... validates c .... end Up until last version of mongoid this worked (with little hack) and data would be saved to my_pages collection. Because of some problem, they no longer support this behaviour and data always gets saved to dc_pages collection. When explaining my problem, they 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. 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 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 You can see my pain. Basic source file would of course be backed into gem and therefor becomes a moving target. Please help me with better solution. by TheR -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.