我正在建立一个管理牙医和地点的应用程序。我刚刚完成了位置显示页面并添加了代码以显示该位置的所有从业者列表。但是,当我呈现页面时,它将整个哈希(locations.practitioner.each)转储到格式化列表上方。如何使散列消失?
这是我的show.html.erb
<p>
<b>Location name:</b>
<%= @location.location_name %>
</p>
<p>
<b>Location id:</b>
<%= @location.id %>
</p>
<p><strong>Practitioners at this Location</strong></p>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Role</th>
<th>Production Goal</th>
<th></th>
</tr>
<%= @location.practitioner.each do |practitioner| %>
<tr>
<td><%= practitioner.first_name %></td>
<td><%= practitioner.last_name %></td>
<td><%= practitioner.role %></td>
<td><%= practitioner.production_goal %></td>
<td><%= link_to "Edit", edit_practitioner_path(practitioner) %></td>
</tr>
<% end %>
</table>
以下是页面的外观......
Location name: Waterview
Location id: 1
Practitioners at this Location
[#<Practitioner id: 1, first_name: "Dr. Robert", last_name: "Anjoux", role: "Dentist", production_goal: 10000, location_id: 1, created_at: "2013-03-26 17:34:38", updated_at: "2013-03-26 21:52:37">,
#<Practitioner id: 3, first_name: "Smantha", last_name: "Hickleberry", role: "Hygenist", production_goal: 4800, location_id: 1, created_at: "2013-03-26 21:49:46", updated_at: "2013-03-26 21:49:46">,
#<Practitioner id: 4, first_name: "Dr. Sandra", last_name: "Prenger", role: "Dentist", production_goal: 22000, location_id: 1, created_at: "2013-03-26 22:05:38", updated_at: "2013-03-26 22:05:38">]
**First Name Last Name Role Production Goal**
Dr. Robert Anjoux Dentist 10000 Edit
Smantha Hickleberry Hygenist 4800 Edit
Dr. Sandra Prenger Dentist 22000 Edit
我做错了什么?我只是表格列表......
丹尼斯
答案 0 :(得分:11)
这一行是你的问题。您正在使用“=”符号显示Ruby语句的输出:
<%= @location.practitioner.each do |practitioner| %>
将其更改为:
<% @location.practitioner.each do |practitioner| %>
答案 1 :(得分:3)
不带'='符号写出:
<% @location.practitioner.each do |practitioner| %>
简短说明:
“ERB将对此进行评估”:
<% %>
“ERB将评估并输出”:
<%= %>