2016-05-01 5 views
0

Ich kann Aufgaben zu meiner Seite hinzufügen, jedoch nur die erste Aufgabe wird in der Tabelle angezeigt. Der Rest wird als normaler, unformatierter Text hinzugefügt.Rails 4 ToDo-Liste, Hinzufügen von Zeilen zur Tabelle

Hier ist meine home.html.erb

<%= content_for :title, "Home" %> 
<h1>Things To Do</h1> 

<div class="container" id="table-width"> 
<% if @tasks.empty? %> 
<span>There are no tasks at the moment!</span> 
<% else %> 
    <table class="table"> 
    <thead> 
     <td>Task</td> 
     <td>Note</td> 
     <td>Created At</td> 
    </thead> 
    <tbody> 
     <% @tasks.each do |task| %> 
     <tr> 
     <td><%= task.title %></td> 
     <td><%= task.note %></td> 
     <td><%= task.created_at.strftime("%A,%B,%Y") %></td> 
     </tr> 
    </tbody> 
    </table> 
    <% end %> 
<% end %> 
<%= link_to "New Task", new_path, class: "btn btn-primary" %> 
</div> 

Und hier ist mein new.html.erb

<h1>Write your task here</h1> 

<div> 
<%= form_for(@task) do |f| %> 
<div class="form-group"> 
<%= f.label :title %> 
<%= f.text_field :title, class: "form-control" %> 
</div> 
<div class="form-group"> 
<%= f.label :note %> 
<%= f.text_area :note, class: "form-control" %> 
</div> 
</div> 

<%= f.submit "Create Task", class: "btn btn-primary" %> 
<% end %> 
+0

Hallo Armen, wie hast du '@ Aufgaben' in Ihrem Controller definiert? –

+0

Können Sie einen Screenshot von dem, was passiert, veröffentlichen? – Pavan

Antwort

1

Sie eine Schleife beginnen bei <% @tasks.each do |task| %> Sie die Schleife beenden sollten, bevor Sie das Ende Tabelle, wie folgt:

<tbody> 
     <% @tasks.each do |task| %> 
     <tr> 
      <td><%= task.title %></td> 
      <td><%= task.note %></td> 
      <td><%= task.created_at.strftime("%A,%B,%Y") %></td> 
     </tr> 
     <% end %> #this ends the @task.each do loop 
    </tbody> 
    </table> 
<% end %> #this ends the if else conditional 
+1

Genau das habe ich gebraucht! – mycellius

Verwandte Themen