我目前正在學習rails並致力於確定每個人的第一個rails應用程序,一個簡單的待辦事項列表。我需要實現項目旁邊的複選框以表明它們是否完整。每個項目在其模型中都有一個名爲「completed」的布爾屬性。我在搜索過程中發現了一些複選框問題,但在索引視圖的上下文中沒有解釋語法。索引視圖中的複選框實時更新
此外,我真的希望複選框沒有提交按鈕工作。我知道我可以使用AngularJS的ng模型來完成這樣的事情,但我不認爲這麼實現角度對於這麼小的事情是實際的,我不知道角度如何與rails一起工作。
如果有人能給我一個正確的方向指針,將不勝感激。這裏是我的index.html.erb供參考。
<h1>
To Do List
</h1>
<table>
<tr>
<% @todo_items.each do |item| %>
<!-- Checkbox here -->
<tc style="<%= 'text-decoration: line-through' if item.completed %>">
<%= link_to item.title, item %>
</tc>
<tc>
<%= item.description %>
</tc>
<tc>
<%= link_to "Edit", edit_todo_item_path(item) %>
</tc>
<tc>
<%= link_to "Delete",item, data:{:confirm => "Are you sure you want to delete this item?"}, :method => :delete %>
</tc>
<hr/>
<% end %>
</tr>
</table>
<p>
<%= link_to "Add Item", new_todo_item_path %>
</p>