# Comment.user associations with acts\_as\_commentable

**URL:** <https://www.ruby-forum.com/t/comment-user-associations-with-acts-as-commentable/133111>\
**Category:** Rails\
**Created:** [March 27, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/comment-user-associations-with-acts-as-commentable/133111 "2008-03-27T21:19:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [March 27, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/comment-user-associations-with-acts-as-commentable/133111/1 "2008-03-27T21:19:16Z")

</div>

I’m using acts\_as\_commentable and running in to a problem when trying to  
access objects associated with the comment.user.

For example: My app has groups, and a group belongs to a user. If I  
write group.user.comments, I’ll see a hash for every comment that the  
group.user has made. However, if I try comment.user.groups, ActiveRecord  
tells me that the ‘groups’ method doesn’t exist for user. The ‘groups’  
method does exist when I write user.groups, however. So I’m betting this  
has something to do with the polymorphic associations in  
acts\_as\_commentable; but at the moment I don’t understand how to make  
comments.user.groups work the way I want it to. Does anyone know what  
I’m missing?

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [April 6, 2008, 1:49pm UTC](https://www.ruby-forum.com/t/comment-user-associations-with-acts-as-commentable/133111/2 "2008-04-06T13:49:31Z")

</div>

Neil C. wrote:

> I’m using acts\_as\_commentable and running in to a problem when trying to  
> access objects associated with the comment.user.
> 
> For example: My app has groups, and a group belongs to a user. If I  
> write group.user.comments, I’ll see a hash for every comment that the  
> group.user has made. However, if I try comment.user.groups, ActiveRecord  
> tells me that the ‘groups’ method doesn’t exist for user. The ‘groups’  
> method does exist when I write user.groups, however. So I’m betting this  
> has something to do with the polymorphic associations in  
> acts\_as\_commentable; but at the moment I don’t understand how to make  
> comments.user.groups work the way I want it to. Does anyone know what  
> I’m missing?

I finally fixed this by creating my own commentable associations. I  
don’t know why I had to do so - maybe it’s something to do with how  
plugins inherit from activerecord - but my comment.user.groups  
associations are now working just fine.

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [September 8, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/comment-user-associations-with-acts-as-commentable/133111/3 "2008-09-08T15:43:10Z")

</div>

Hi Neil,  
I think I am having exactly this problem and I was wondering if you  
could tell me what you mean by “I finally fixed this by creating my  
own commentable associations.” ?

In my app, I have events and users, both of which act\_as\_commentable.  
When I try to load comment.user.avatar (\<-- an act\_as\_attachment  
image) I get the undefined method error (in my case ‘avatar’).

thanks

Paul

On Apr 6, 12:49 pm, Neil C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [September 8, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/comment-user-associations-with-acts-as-commentable/133111/4 "2008-09-08T16:19:27Z")

</div>

Paul wrote:

> Hi Neil,  
> I think I am having exactly this problem and I was wondering if you  
> could tell me what you mean by “I finally fixed this by creating my  
> own commentable associations.” ?
> 
> In my app, I have events and users, both of which act\_as\_commentable.  
> When I try to load comment.user.avatar (\<-- an act\_as\_attachment  
> image) I get the undefined method error (in my case ‘avatar’).
> 
> thanks
> 
> Paul
> 
> On Apr 6, 12:49 pm, Neil C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi Paul

It’s been ages since I fixed this and I’m not even using polymorphic  
comments anymore. However, I believe the problem was fixed by simply  
creating my own polymorphic comments and dropping the plugin altogether.  
This is pretty easy to do. Just run the migration, create the comment  
model, set up the associations between the user and the comment, and  
that’s it. The plugin (something to do with it being loaded as a plugin  
and a separate module, presumably) seemed to break the associations that  
belonged to the user.

Hope that helps
