I need some newb help here. I am making a quick app to learn on to hold my collection of cards. I have a card database with a ton of fields, and also a collection table. my collection has_many cards, and cards belongs_to collection. I''m trying to list out cards in my collection, and pulling the card "title" from the "card" database. I know my relation''s are setup because I can do this in other methods under my collection model, but I can''t seem to do the following, which I thought would pull the "title" with the according card_id <% @collections.each do |c| %> <li><%= c.card.title %></li> I think I''m trying to do something the each do will not allow. just as an fyi I can pull everything from my collection table ie: c.card_id or c.qty etc.. but trying to tap in to the other table it bawks. Cheers -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Shaffer
2010-Apr-29 14:30 UTC
Re: database relation''s tying to pull data from another table
You need to add another loop for the cards: <% @collections.each do |collection| %> <% collection.cards.each do |card| %> <li><%= card.title %></li> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thx I figured it was something that simple On Apr 29, 7:30 am, Tim Shaffer <t...-PGA7PSC7mq/3MY4plGdlAw@public.gmane.org> wrote:> You need to add another loop for the cards: > > <% @collections.each do |collection| %> > <% collection.cards.each do |card| %> > <li><%= card.title %></li> > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.