Database relation's tying to pull data from another table

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

  • <%= c.card.title %>
  • 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 need to add another loop for the cards:

    <% @collections.each do |collection| %>
    <% collection.cards.each do |card| %>

  • <%= card.title %>
  • Thx I figured it was something that simple

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs