My use case relies on having the Member class inherit from User, and Member own a bunch of other classes which I would like to be commentable, including Game.
I would like comment.recipient set, in order to facilitate email notifications, etc. (I tested leaving it unset, and that broke some views downstream. I will pursue that approach further if need be.) So, I assert that user_game_url is appropriate, but the route fails. Do I need to add a route to make that work? I haven't found a matching route in the output from rake routes, but don't know if there's some other mechanism at work. I may be lacking some other clue, which is why I'm describing the use case. Thanks for your patience. On Mon, Jun 1, 2009 at 7:09 AM, Bruno Bornsztein <[email protected]> wrote: > I'm confused. You want user_game_url and commentable_url is returning > user_game_url? What's the problem? > > > On Sat, May 30, 2009 at 3:11 PM, mike muldoon <[email protected]> > wrote: >> >> I was already in there, trying various permutations for just such a >> Game special case. This generates 'member_game_url': >> >> def commentable_url(comment) >> if comment.recipient && comment.commentable >> if comment.commentable_type == "Game" >> debugger >> polymorphic_url([comment.commentable.member, >> >> comment.commentable])+"#comment_#{comment.id}" >> elsif ... >> >> member_game_url has no route because Member is just a model, and has >> no controller. Put another way, Members don't own Photos, Users do. >> The desired route is user_game_url, which has me thinking that maybe >> LostyJai's suggestion would be appropriate, as this isn't the result >> of a bug in polymorphic_url. >> >> Thoughts? >> >> >> On Fri, May 29, 2009 at 6:33 PM, Bruno Bornsztein >> <[email protected]> wrote: >> > Look at commentable_url in BaseHelper. It calls: >> > polymorphic_url([comment.recipient, >> > comment.commentable])+"#comment_#{comment.id}" >> > So it uses the recipient of the comment (which is a user) for comments >> > on >> > anything other than users. You can overwrite that method to make an >> > exception for Games, something like (pseudo-code): >> > if comment.commentable_type == "Game" >> > polymorphic_url([comment.commentable.member, comment]) >> > #comment.commentable should return a Game >> > end >> > Good luck, >> > Bruno >> > On Fri, May 29, 2009 at 8:06 PM, LostyJai <[email protected]> >> > wrote: >> >> >> >> Have you defined your model as a subclass of user in routes? >> >> >> >> On May 30, 8:52 am, angrysponge <[email protected]> wrote: >> >> > I have a Game model which I would like to enable comments for. Games >> >> > are owned by Members, which is a subclass of User. The relevant model >> >> > code needed thus far: >> >> > >> >> > class Game < ActiveRecord::Base >> >> > belongs_to :member >> >> > acts_as_commentable >> >> > def owner >> >> > self.member.becomes(User) >> >> > end >> >> > >> >> > class Member < User >> >> > has_many :games >> >> > >> >> > Saving a comment for a Game generates this error: >> >> > NoMethodError in CommentsController#create >> >> > undefined method `user_game_url' for #<CommentsController:0xb6daef9c> >> >> > >> >> > When adding a comment to a Photo, polymorphic_url() returns >> >> > 'user_photo_url', so 'user_game_url' looks reasonable, except that >> >> > Users don't own Games, Members do. >> >> > >> >> > Am I missing some route details for my Game model? >> >> > >> >> > Any suggestions? >> >> > Mike >> >> >> > >> > >> > > >> > >> >> > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CommunityEngine" 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/communityengine?hl=en -~----------~----~----~----~------~----~------~--~---
