Ruby on Rails group_by (wie man Ereignisse nach Monat gruppiert)

Hey Leute, ich bin neu auf Schienen. Ich habe einen Controller, der Ereignisse erstellt, und ich möchte sie nach Monat gruppieren (dem Monat dieses Ereignisdatums). Ich benutze Schienen 4 hier ist mein Code.

Das ist mein Controller

def index
 @events = Event.all
 @event_months = @events.group_by { |t| t.due_at.beginning_of_month }
end

Dies ist mein Ansichtscode

<% @event_months.each do |month, events| %>
  <h2><%= month.strftime('%B') %></h2>
    <% for event in evetns %>
     <div class='event-card'>
      <a href="<%= event.url %>">
       <div class='event-image'>
        <%= image_tag event.image_url(:normal), :class => 'eimage', :style =>  'width:100%;' %>
       </div>
       <div class='event-content'>
        <h1 class='event-title'><%= event.name %></h1>
        <h2 class='event-place'><%= event.where %></h2>
        <h3 class='event-time-date'><%= event.start_time.strftime("%B %d @ %I:%M %p") %></h3>
       </div>
      </a>
     </div>
   <% end %>
 <%= link_to 'Show', event %>
 <%= link_to 'Edit', edit_event_path(event) %>
 <%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>

Danke im Voraus.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage