# Newbie confused by div\_for

**URL:** <https://www.ruby-forum.com/t/newbie-confused-by-div-for/163299>\
**Category:** Rails\
**Created:** [March 18, 2009, 11:52pm UTC](https://www.ruby-forum.com/t/newbie-confused-by-div-for/163299 "2009-03-18T23:52:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [March 18, 2009, 11:52pm UTC](https://www.ruby-forum.com/t/newbie-confused-by-div-for/163299/1 "2009-03-18T23:52:20Z")

</div>

Hi,

Absolute Rails beginner here.

in app/views/players/show.html.rb:

\<%= render :partial =\> @player.items %\>

in app/views/items/\_item.html.erb

\<% div\_for item do %\>- \<%= h(item.name) %\>
\<% end %\>

That works fine. I’m trying to get rid of the partial, so I do  
something like:

in app/views/players/show.html.rb

\<% div\_for @player.items do %\>- \<%= h(item.name) %\>
\<% end %\>

That doesn’t work with error “undefined local variable or method `item’”

How do I iterate over the items?

From script/console:

> > player.items  
> > =\> [#\<Item id: 4, name: “Chopsticks”, quantity: nil, player\_id: 2,  
> > created\_at: “2009-03-18 16:39:42”, updated\_at: “2009-03-18 16:39:42”\>,  
> > #\<Item id: 5, name: “Bowl”, quantity: nil, player\_id: 2, created\_at:  
> > “2009-03-18 17:04:12”, updated\_at: “2009-03-18 17:04:12”\>]

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [March 18, 2009, 11:59pm UTC](https://www.ruby-forum.com/t/newbie-confused-by-div-for/163299/2 "2009-03-18T23:59:58Z")

</div>

On Mar 18, 2009, at 3:52 PM, Alex Chekholko wrote:

> something like:
> 
> That doesn’t work with error “undefined local variable or method  
> `item’”
> 
> How do I iterate over the items?

\<% @player.items.each do |item| %\> \<% div\_for item do %\> - \<%= h item.name %\>
 \<% end %\> \<% end %\>

---

<div class="post-metadata">

**Author:** ![combas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@combas](https://www.ruby-forum.com/u/combas)\
**Post date:** [March 19, 2009, 12:33am UTC](https://www.ruby-forum.com/t/newbie-confused-by-div-for/163299/3 "2009-03-19T00:33:30Z")

</div>

Philip H. wrote:

> On Mar 18, 2009, at 3:52 PM, Alex Chekholko wrote:
> 
> > That doesn’t work with error “undefined local variable or method  
> > `item’”
> > 
> > How do I iterate over the items?
> 
> \<% @player.items.each do |item| %\> \<% div\_for item do %\> - \<%= h item.name %\>
> \<% end %\> \<% end %\>

Thanks, I get it now!
