I have an active record class that looks like the following: class TemplatePhotoSlot < ActiveRecord::Base belongs_to :template # used in the autoflow photo best fit algorithm def <=>(other) self.slot_num < other.slot_num ? -1 : 1 end def area # gets area of the photo_slot based on width and height width*height end end For some reason, when I call "sort" on an array of these items it will work the first couple of times. Then, it will stop working and it tells me: undefined method `<=>'' for #<TemplatePhotoSlot:0x4932d00> anybody have any idea what might be happening? -- 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 -~----------~----~----~----~------~----~------~--~---
I commented out the "<=>" method and it turns out that its happening with "area" method now as well.. Anybody experience this behavior before where, when your server first boots up, the methods are working, and then all of a sudden they stop? -- 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 -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Sep-16 02:24 UTC
Re: <=> comparison operator method undefined in AR class
I had the same behavior with acts_as_commentable. Acts_as_commentable belongs_to :user, and I could not access any methods I had defined in User after the first request. I solved it (thought I don''t know why) by moving comment.rb from /vendor/acts_as_commentable/lib to /app/models. I don''t know if this is related to your problem, but the behavior sounds awful similar. Aryk Grosz wrote:> I commented out the "<=>" method and it turns out that its happening > with "area" method now as well.. > > > Anybody experience this behavior before where, when your server first > boots up, the methods are working, and then all of a sudden they stop? >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmm interesting, could this be happening because Im using "extend" on an object, not the actual singleton class? If so how else can I extend an AR object with module methods? William Pratt wrote:> I had the same behavior with acts_as_commentable. Acts_as_commentable > belongs_to :user, and I could not access any methods I had defined in > User after the first request. I solved it (thought I don''t know why) by > moving comment.rb from /vendor/acts_as_commentable/lib to /app/models. I > don''t know if this is related to your problem, but the behavior sounds > awful similar.-- 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 -~----------~----~----~----~------~----~------~--~---
Not really on point here but if slot_num is something that already supports <=>, you can tidy up your method: def <=>(other) self.slot_num <=> other.slot_num end As for the original problem, are you working in the development environment? There are some odd issues that can creep into development that have primarily to do with which classes are cached and which are reloaded. The good news is that they don''t (typically) effect production code. To feel safe, it''d probably be worth building some good unit tests. On Sep 15, 8:39 pm, Aryk Grosz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have an active record class that looks like the following: > > class TemplatePhotoSlot < ActiveRecord::Base > belongs_to :template > > # used in the autoflow photo best fit algorithm > def <=>(other) > self.slot_num < other.slot_num ? -1 : 1 > end > > def area # gets area of the photo_slot based on width and height > width*height > end > > end > > For some reason, when I call "sort" on an array of these items it will > work the first couple of times. Then, it will stop working and it tells > me: > > undefined method `<=>'' for #<TemplatePhotoSlot:0x4932d00> > > anybody have any idea what might be happening? > -- > 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 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 -~----------~----~----~----~------~----~------~--~---