ldgalea-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Sep-26 03:26 UTC
Missing assocation methods (public_instance_methods.length == 0 for an active record model)
Hi all, I''m getting a weird "transient" error I''m hoping someone can shed some light on. In short, the first time view a particular page all is well. The second time around, I get a bunch of active record model objects with no public_instance_methods, so all code relying on that fails. Server restart is required to fix it. I have a method in one of my models that goes through several associated models, iterates over the associated model objects and further iterates into associated models on those to return some distantly related model objects. It works great.. but only once for every server load. If I refresh the page, subsequent calls to the accessor methods for the associations have no methods!! So I get undefined method for something that clearly existed just one refresh ago! To give some more details, I have a Volunteer which has VolunteerApplications which each have an Opportunity which each have an Organization. I want to get the organizations for a given volunteer.. So I do so via has_many :opportunities, :through => :volunteer_applications which has created the opportunities method for me. I call that and iterate over each and call organization on each (which was created by: belongs_to :organization ) But upon refresh the organization accessor doesn''t exist for opportunity, nor does any other. Any clues? Ideas of how to better debug this? I''ve confirmed via debugger that the attributes are all set on the model object, but it has none of the association methods added by has_many, belongs_to, etc. I''ve also confirmed that belongs_to, etc are in fact being run. Thanks in advance! -- Luke --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vince
2007-Sep-26 03:49 UTC
Re: Missing assocation methods (public_instance_methods.length == 0 for an active record model)
I''d just like to add that this problem doesn''t occur in the test or production environments, only development. Also, we are running Rails 1.2.3 over Ruby 1.8.5 On Sep 25, 11:26 pm, "ldga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <ldga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I''m getting a weird "transient" error I''m hoping someone can shed some > light on. > > In short, the first time view a particular page all is well. The > second time around, I get a bunch of active record model objects with > no public_instance_methods, so all code relying on that fails. Server > restart is required to fix it. > > I have a method in one of my models that goes through several > associated models, iterates over the associated model objects and > further iterates into associated models on those to return some > distantly related model objects. > > It works great.. but only once for every server load. If I refresh the > page, subsequent calls to the accessor methods for the associations > have no methods!! So I get undefined method for something that clearly > existed just one refresh ago! > > To give some more details, I have a Volunteer which has > VolunteerApplications which each have an Opportunity which each have > an Organization. > > I want to get the organizations for a given volunteer.. So I do so via > > has_many :opportunities, :through => :volunteer_applications > > which has created the opportunities method for me. I call that and > iterate over each and call organization on each (which was created by: > belongs_to :organization ) > > But upon refresh the organization accessor doesn''t exist for > opportunity, nor does any other. > > Any clues? Ideas of how to better debug this? I''ve confirmed via > debugger that the attributes are all set on the model object, but it > has none of the association methods added by has_many, belongs_to, > etc. > > I''ve also confirmed that belongs_to, etc are in fact being run. > > Thanks in advance! > -- Luke--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ldgalea-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Sep-26 04:47 UTC
Re: Missing assocation methods (public_instance_methods.length == 0 for an active record model)
Solved. Once upon a time this would have involved using model :blah in the Controller.. But I hear that''s deprecated. So I just required the models.. and it''s fine. Not an easy thing to troubleshoot though.. -- Luke --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---