2

我正在构建一个应用程序来管理牙医和位置。我刚刚完成了位置显示页面并添加了代码以显示该位置所有从业者的列表。但是,当我呈现页面时,它会将整个哈希(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

我究竟做错了什么?我只是表格列表...

丹尼斯

4

2 回答 2

11

这条线是你的问题。您正在使用“=”符号来显示 Ruby 语句的输出:

<%= @location.practitioner.each do |practitioner| %>

将其更改为:

<% @location.practitioner.each do |practitioner| %>
于 2013-03-26T23:20:09.707 回答
3

写成不带“=”符号:

<% @location.practitioner.each do |practitioner| %>

简短说明:

“ERB 将对此进行评估”:

<%  %>

“ERB 将评估并输出这个”:

<%=  %>
于 2013-03-26T23:19:55.017 回答