我有一个employee
对象,我只想在show.html.erb
文件中显示密钥列表和相关值。这是我目前所拥有的,但如何通过for
循环完成此操作?
<table class="table table-striped">
<tr>
<th>Item</th>
<th>Value</th>
</tr>
<tr>
<td>Name</td>
<td><%= @employee.name %></td>
</tr>
<tr>
<td>Email</td>
<td><%= @employee.email %></td>
</tr>
<tr>
<td>Job Code</td>
<td><%= @employee.job_code %></td>
</tr>
...
</table>
答案 0 :(得分:2)
<% @employee.attributes.each do |key, value| %>
<tr>
<td><%= key.gsub('_', ' ').titleize %></td>
<td><%= value %></td>
</tr>
<% end %>