Hey, So I keep getting "undefined method `each'' for #<Definition: 0x28fa154>". The call that gets made returns 1 word object with 2 definition objects. I can verify both definition objects get returned with all there attributes because I can output data like this: <% @word.definitions.each do |h| %> <p> <%=h h.definition %> </p> <p> <%=h h.id %> </p> <% end %> But I''d like to not write out every definition attribute so I attempt to loop those as well like this: <% @word.definitions.each do |h| %> <% h.each do |i| %> <p> <%=h h.i %> </p> <% end %> <% end %> But get the above mentioned error. My guess is I''m getting a returned data type that is not an array? So I can''t loop them the same way? Your suggestions would be very helpful, thanks.
2009/8/31 brianp <brian.o.pearce@gmail.com>:> > Hey, > So I keep getting "undefined method `each' for #<Definition: > 0x28fa154>". The call that gets made returns 1 word object with 2 > definition objects. I can verify both definition objects get returned > with all there attributes because I can output data like this: > > <% @word.definitions.each do |h| %> > <p> > <%=h h.definition %> > </p> > <p> > <%=h h.id %> > </p> > <% end %> > > But I'd like to not write out every definition attribute so I attempt > to loop those as well like this: > > <% @word.definitions.each do |h| %> > <% h.each do |i| %> > <p> > <%=h h.i %> > </p> > <% end %> > <% end %> > > But get the above mentioned error. My guess is I'm getting a returned > data type that is not an array? So I can't loop them the same way? > Your suggestions would be very helpful, thanks.If you are trying to iterate through the columns of the definition object object you can use the content_columns array, so h.content_columns.each do |column| # column.name contains the column name # h.send(column.name) will return the value end Colin --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Found my problem: I needed to call the attributes array directly on each definition object. <% @word.definitions.each do |h| %> <% h.attributes.each do |i| %> <p> <%=h i %> </p> <% end %> <% end %> On Aug 31, 2:04 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/8/31 brianp <brian.o.pea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > Hey, > > So I keep getting "undefined method `each'' for #<Definition: > > 0x28fa154>". The call that gets made returns 1 word object with 2 > > definition objects. I can verify both definition objects get returned > > with all there attributes because I can output data like this: > > > <% @word.definitions.eachdo |h| %> > > <p> > > <%=h h.definition %> > > </p> > > <p> > > <%=h h.id %> > > </p> > > <% end %> > > > But I''d like to not write out every definition attribute so I attempt > > to loop those as well like this: > > > <% @word.definitions.eachdo |h| %> > > <% h.eachdo |i| %> > > <p> > > <%=h h.i %> > > </p> > > <% end %> > > <% end %> > > > But get the above mentioned error. My guess is I''m getting a returned > > data type that is not an array? So I can''t loop them the same way? > > Your suggestions would be very helpful, thanks. > > If you are trying to iterate through the columns of the definition > object object you can use the content_columns array, so > h.content_columns.eachdo |column| > # column.name contains the column name > # h.send(column.name) will return the value > end > > Colin