# Netsted each loops

**URL:** <https://www.ruby-forum.com/t/netsted-each-loops/174672>\
**Category:** Rails\
**Created:** [August 31, 2009, 10:44am UTC](https://www.ruby-forum.com/t/netsted-each-loops/174672 "2009-08-31T10:44:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@brianp](https://www.ruby-forum.com/u/brianp)\
**Post date:** [August 31, 2009, 10:44am UTC](https://www.ruby-forum.com/t/netsted-each-loops/174672/1 "2009-08-31T10:44:55Z")

</div>

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| %\>

\<%=h h.definition %\>

  

\<%=h h.id %\>

  
\<% 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| %\>

\<%=h h.i %\>

  
\<% 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.

---

<div class="post-metadata">

**Author:** ![brianp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@brianp](https://www.ruby-forum.com/u/brianp)\
**Post date:** [August 31, 2009, 11:06am UTC](https://www.ruby-forum.com/t/netsted-each-loops/174672/2 "2009-08-31T11:06:35Z")

</div>

2009/8/31 brianp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â Â Â Â Â Â Â Â Â Â Â Â
> 
>   
> Â Â Â Â Â Â Â Â Â Â Â Â 
> 
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \<%=h h.i %\>  
> Â Â Â Â Â Â Â Â Â Â Â Â
> 
>   
> Â Â Â Â Â Â Â Â \<% 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

---

<div class="post-metadata">

**Author:** ![brianp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@brianp](https://www.ruby-forum.com/u/brianp)\
**Post date:** [September 1, 2009, 7:54am UTC](https://www.ruby-forum.com/t/netsted-each-loops/174672/3 "2009-09-01T07:54:21Z")

</div>

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| %\>

\<%=h i %\>

 \<% end %\> \<% end %\>
