0

I can only view the child values in the "show" template using:

<% @guest.plusones.each do |plus| %>
  <%= plus.name %>
  <%= plus.oldness %>
<% end %>

I now need display these values in a table on the "index" template.

How can I do this?

See tables and relationship below:

Plusone table

+--------------+---------+----------+    
|     name     | Oldness | guest_id |
+--------------+---------+----------+    
| Tom Jnr      | Child   |        4 |
| Nancy Miller | Adult   |        5 |
| Ace Flame    | Adult   |        6 |
+--------------+---------+----------+

Guests table
+----+------------+-----------------+
| id |    name    |     Message     |
+----+------------+-----------------+
|  4 | Tom Snr    | Congratulations |
|  5 | Rob Miller | Congrats        |
|  6 | May Flame  | Wow Amazing     |
+----+------------+-----------------+

As there anything that I need to add in the GuestController index method?

Codelove
  • 68
  • 1
  • 8

1 Answers1

0

Try to organize your code like this so you can debug your error easily:

views/guests/index.html.erb

<%= render @guests %>

views/guests/_guest.html.erb

<%= guest.name %>
<%= render guest.plusones %>

views/plusones/_plusone.html.erb

<%= plusone.name %>
DevMarwen
  • 1,626
  • 11
  • 27