2016-05-01 7 views
0

私のページにタスクを追加できますが、最初のタスクだけがテーブルに表示されます。残りの部分は、通常のフォーマットされていないテキストとして追加されます。ここでRails 4 ToDoリスト、テーブルに行を追加する

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

そして、ここで私の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

こんにちは、私はあなたのコントローラで '@タスク'を定義しましたか? –

+0

何が起こっているのスクリーンショットを投稿できますか? – Pavan

答えて

1

であるあなたが終了する前に、ループを終了する必要が<% @tasks.each do |task| %>でループを開始テーブルのように:

<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

これはまさに私が必要としていたものです! – mycellius

関連する問題