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. How do I make the hash go away?
Here's my 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:
<%= @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 will evaluate and output this":
<%= %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.