# Add comments to ALL models (ie automatically add has\_many)

**URL:** <https://www.ruby-forum.com/t/add-comments-to-all-models-ie-automatically-add-has-many/125403>\
**Category:** Rails\
**Created:** [January 8, 2008, 9:21pm UTC](https://www.ruby-forum.com/t/add-comments-to-all-models-ie-automatically-add-has-many/125403 "2008-01-08T21:21:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![uncle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e5b9ba/32.png) [@uncle](https://www.ruby-forum.com/u/uncle)\
**Post date:** [January 8, 2008, 9:21pm UTC](https://www.ruby-forum.com/t/add-comments-to-all-models-ie-automatically-add-has-many/125403/1 "2008-01-08T21:21:45Z")

</div>

I have the acts\_as\_commentable and a bunch of others added to pretty  
much every model, is there a way to automaically add these to EVERY  
model ?

I tried the following but it fails with an error…

ActiveRecord::Base.class\_eval do  
has\_many :notes, :as =\> :model\_with\_notes, :dependent =\> true  
end

fails with…  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active\_record/  
base.rb:1369:in `class_of_active_record_descendant':NoMethodError: undefined method`abstract\_class?’ for Object:Class

---

<div class="post-metadata">

**Author:** ![uncle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e5b9ba/32.png) [@uncle](https://www.ruby-forum.com/u/uncle)\
**Post date:** [January 8, 2008, 10:03pm UTC](https://www.ruby-forum.com/t/add-comments-to-all-models-ie-automatically-add-has-many/125403/2 "2008-01-08T22:03:22Z")

</div>

On Jan 8, 12:21 pm, uncle [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have the acts\_as\_commentable and a bunch of others added to pretty  
> much every model, is there a way to automaically add these to EVERY  
> model ?

Without knowing the details, I would suggest using inheritance.  
Instead of trying to change ActiveRecord::Base, just derive a new  
class from it to hold all the common stuff, then derive your models  
from that class.

///ark
