[英]Ruby on Rails Each… do loop displays the hash
I'm building an app manage dentists and locations. 我正在建立一个管理牙医和地点的应用程序。 I just finished the location show page and added code to display a list of all the practitioners at that location.
我刚刚完成了位置显示页面并添加了代码以显示该位置的所有从业者列表。 However when I render the page, it is dumping the entire hash (locations.practitioner.each) above my formatted list.
但是,当我呈现页面时,它将整个哈希(locations.practitioner.each)转储到格式化列表上方。 How do I make the hash go away?
如何使哈希消失?
Here's my show.html.erb 这是我的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>
And here's how the page looks... 以下是页面的外观......
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
What am I doing wrong? 我究竟做错了什么? I just what the tabular list...
我只是表格列表...
Dennis 丹尼斯
This line is your problem. 这条线是你的问题。 You are using the "=" sign which displays the output of the Ruby statement:
您正在使用“=”符号显示Ruby语句的输出:
<%= @location.practitioner.each do |practitioner| %>
Change it to this: 把它改成这个:
<% @location.practitioner.each do |practitioner| %>
Write it without the '=' symbol: 不带'='符号写它:
<% @location.practitioner.each do |practitioner| %>
Short explanation: 简短说明:
"ERB will evaluate this": “ERB将对此进行评估”:
<% %>
"ERB will evaluate and output this": “ERB将评估并输出”:
<%= %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.