これが私のデータベースからのリストのテーブルを表示するために基本的に使用されるいくつかのコードです。最後の数列は、モデルの特定のブール属性に関連付けられているラジオボタンとチェックボックスにすぎません。チェックボックスとラジオボタンをプログラムしました。しかし、どうすればデータベースの値を表示させることができますか?
index.html.erb:
<h1>Listings</h1>
<table class="datatable">
<tr id="heading" >
<th >id</th>
<th >name</th>
<th>telephone</th>
</tr>
<% @listings.each do |listing| %>
<tr id="body">
<th><%=listing.id%></th>
<th><%= link_to listing.name, edit_listing_path(listing) %></th>
<th><%=listing.telephone%></th>
<%= form_for listing do |f| %>
<td id="keep"><%= f.radio_button :keep, "Keep" %></br>
<%= f.label :keep, "Keep" %>
</td>
<td id="delete"> <%= f.radio_button :keep, "Delete" %></br>
<%= f.label :keep, "Delete" %>
</td>
<td id="checked"><%= f.check_box :checked %></br>
<%= f.label :checked, "checked" %>
</td>
<td id="collected"><%= f.check_box :collected %></br>
<%= f.label :collected, "collected" %>
</td>
<td id="digitized"><%= f.check_box digitized %></br>
<%= f.label :digitized, "digitized" %>
</td>
<td id="in_db"><%= f.check_box :in_database %></br>
<%= f.label :database, "database" %>
</td>
<td id="submit"><%= f.submit "update" %></br>
</td>
<% end %>
</tr>
<% end %>
</table>
また、ここで「フォーム」を選択する理由は、最終的にここでデータを表示する方法を理解した後、ユーザーがチェックボックスの値を変更した場合に、このビューでもモデルのデータを「更新」するためです。しかし、モデルの値を表示する方法を学んだら、それについて説明します。
ありがとう