Hi, Absolute Rails beginner here. in app/views/players/show.html.rb: <%= render :partial => @player.items %> in app/views/items/_item.html.erb <ul> <% div_for item do %> <li> <%= h(item.name) %> </li> <% end %> </ul> That works fine. I''m trying to get rid of the partial, so I do something like: in app/views/players/show.html.rb <ul> <% div_for @player.items do %> <li> <%= h(item.name) %> </li> <% end %> </ul> 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">] -- 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 -~----------~----~----~----~------~----~------~--~---
On Mar 18, 2009, at 3:52 PM, Alex Chekholko wrote:> > Hi, > > Absolute Rails beginner here. > > in app/views/players/show.html.rb: > > <%= render :partial => @player.items %> > > in app/views/items/_item.html.erb > > <ul> > <% div_for item do %> > <li> > <%= h(item.name) %> > </li> > <% end %> > </ul> > > > That works fine. I''m trying to get rid of the partial, so I do > something like: > > in app/views/players/show.html.rb > > <ul> > <% div_for @player.items do %> > <li> > <%= h(item.name) %> > </li> > <% end %> > </ul> > > That doesn''t work with error "undefined local variable or method > `item''" > > How do I iterate over the items?<ul> <% @player.items.each do |item| %> <% div_for item do %> <li><%= h item.name %></li> <% end %> <% end %> </ul> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom 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? > > <ul> > <% @player.items.each do |item| %> > <% div_for item do %> > <li><%= h item.name %></li> > <% end %> > <% end %> > </ul>Thanks, I get it now! -- 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 -~----------~----~----~----~------~----~------~--~---