Many thanks... #2 is what I was thinking, but I don't understand how
lib/commentable.rb would get loaded in that case?


On Oct 23, 1:12 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> Scott Johnson wrote:
> > On Oct 23, 11:11 am, Marnen Laibow-Koser <rails-mailing-l...@andreas-
> > s.net> wrote:
> >> Define it as an ActiveRecord::Base class method.
>
> > Sure, but where? In lib/* somewhere? I'll need it to get loaded before
> > any of these models get loaded. (Or I would have to add a 'require' to
> > each commentable model.)
>
> You have a number of choices:
>
> 1.
> /lib/commentable.rb
> module Commentable
>   def self.included(base)
>     base.has_many :subscriptions, :as => :subscribable
>     # and so on
>   end
> end
>
> /app/models/blog_post.rb
> class BlogPost < AR::B
>   include Commentable
>
>   # rest of class definition
> end
>
> 2.
> /lib/commentable.rb
> # as in 1, but after the end of the module (or in environment.rb):
> class ActiveRecord::Base
>   def self.acts_as_commentable
>     include Commentable
>   end
> end
>
> /app/models/blog_post.rb
> class BlogPost < AR::B
>   acts_as_commentable
> end
>
> 3 (probably not recommended).
> /config/environment.rb
> class ActiveRecord::Base
>   def self.acts_as_commentable
>     has_many :subscriptions, ;as => :subscribable
>     # and the other has_manys
>   end
> end
>
> 4.  Write an acts_as plugin (but call it something else -- I think
> acts_as_commentable is already taken as a plugin name).
>
> Does that help?
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> [email protected]
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to