Nested views in a view Rails
<p>How can I show the attendances that belong to each event under each event?</p>

<p>Event.rb:</p>

<pre><code>class Event &lt; ActiveRecord::Base
  has_many :attendances, dependent: :destroy
</code></pre>

<p>Events/index:</p>

<pre><code>%h1 Listing events
%table
  %thead
    %tr
      %th Starts at
      %th Duration

  %tbody
    - @events.each do |event|
      %tr
        %td= event.starts_at
        %td= event.duration

%br
</code></pre>

<p>I tried this code, but it renders totally all attendances under each event:</p>

<pre><code>%table
  %thead
    %tr
      %th Starts at
      %th Duration

  %tbody
    - @events.each do |event|
      %tr
        %td= event.starts_at
        %td= event.duration
        - @attendances.each do |attendance|
          %tr
            %td= attendance.guest
            %td= attendance.attendance_rate
            %td= attendance.event
%br
</code></pre>

<p>It looks like I must change something in the array &amp; in controller?</p>