0

This site is rendering like this:

Product Listings

Test

test

$1.00


Test

test

$1.00


Hello!

This is a description.

$125135.13

test.gif


Product #1

Product #1 description.

$100.00

N/a

[#, photo: "", created_at: "2013-03-16 06:17:30", updated_at: "2013-03-16 06:17:30">, #, photo: "", created_at: "2013-03-16 06:17:48", updated_at: "2013-03-16 06:17:48">, #, photo: "test.gif", created_at: "2013-03-16 06:24:13", updated_at: "2013-03-16 06:24:13">, #, photo: "N/a", created_at: "2013-03-16 13:16:35", updated_at: "2013-03-16 13:16:35">]

index.html.erb

<h1>Product Listings</h1>
        <%= @products.each do |p| %>
            <li><%= p.name %></li>
            <li><%= p.description %></li>
            <li><%= sprintf("$%0.02f", p.price) %></li>
            <li><%= p.photo %></li>
        <% end %>

Any idea on how to make Rails only display the iterations through the model and not the hash at the bottom?

4

1 回答 1

6

这是你的问题:

<%= @products.each do |p| %>

那应该是:

<% @products.each do |p| %>

因为等号<%=导致它输出返回值,而不仅仅是作为流控制。

于 2013-03-16T13:31:05.010 回答