I get this error if no relational data is present: undefined method `notes'' for #<Array:0x226cc4c> Here is the code that causes the error: @notes = @account.notes If I call this method through the script/console I get account = Account.find(3) => #<Account id: 3, ...>>> account.notes=> [] I get the same error if I don''t declare the @notes var and access the notes collection through the controller within the haml template ie @account.notes.each do |n| ... I am puzzled. Thanks for the help -- 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 -~----------~----~----~----~------~----~------~--~---
ruben.pierich-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Apr-17 00:03 UTC
Re: undefined method exception if no data is present
It looks like your trying to call a notes method on an instance of an Array. I don''t think Arrays have a notes method. Chris Olsen wrote:> I get this error if no relational data is present: > undefined method `notes'' for #<Array:0x226cc4c> > > Here is the code that causes the error: > @notes = @account.notes > > If I call this method through the script/console I get > account = Account.find(3) > => #<Account id: 3, ...> > >> account.notes > => [] > > I get the same error if I don''t declare the @notes var and access the > notes collection through the controller within the haml template ie > @account.notes.each do |n| ... > > I am puzzled. > > Thanks for the help > -- > 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 -~----------~----~----~----~------~----~------~--~---
Right you are. It was a mistype of :all rather than :first in the lookup. Thanks -- 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 -~----------~----~----~----~------~----~------~--~---