Hi Folks... Longtime Radiant user, just getting started with Mental  
Extensions.

I am creating an extension for posting and managing Comments. I've  
created the Comment model, my controllers, and views in the new  
Extension, but I'm having trouble extending Radiant's built-in Page  
model to include the proper has_many association.

In a nutshell: I want to include a has_many association in the Page  
model.

It seems like I should be able to just open the Page class and  
include my association like this:

   class Page < ActiveRecord::Base
     has_many :comments
   end

in ../extensions/comments/app/models/page.rb

This doesn't work, of course. It doesn't return an error - as far as  
I can tell it just doesn't do anything. Referencing @page.comments in  
my views throws an error: "undefined method `comments'". I presume  
it's because it is ignoring this class.

I've also tried several module mix-ins that haven't worked (i.e.  
packaging a PageExtender module and then including it in Page). For  
example:

   module PageExtender
     def self.included(base)
       base.extend(ClassMethods)
     end
     module ClassMethods
       has_many :comments
     end
   end

in ../extensions/comments/lib/page_extender.rb

And then

   def activate
     ...
     Page.send :include, PageExtender
   end

in ../extensions/comments/comments_extension.rb

But this terminates with
~/Sites/radiant.mental/vendor/extensions/comments/lib/ 
page_extender.rb:8: undefined method `has_many' for  
PageExtender::ClassMethods:Module (NoMethodError)

Any ideas?

Thanks,
Ryan Heneise
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to