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? -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Neil Cauldwell
2008-Apr-06 11:49 UTC
Re: comment.user associations with acts_as_commentable
Neil Cauldwell 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. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Neil Cauldwell
2008-Sep-08 14:19 UTC
Re: comment.user associations with acts_as_commentable
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 Cauldwell <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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 -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---