0

我有一个正在使用 Rails 3.2 构建的婴儿礼物注册表。有一个注册模型和一个嵌套在注册模型下的当前模型。除显示页面外,一切都 100% 正常工作。

当用户创建注册表时,他/她可以通过添加礼物标签添加礼物(他/她想要多少),但问题出在显示页面中,它只显示第一个礼物,因为我也想要它。其余部分以纯非格式化文本显示。

请问有什么帮助吗?我希望它以表格格式显示。

这是我的代码:这是注册表单:

<%= nested_form_for(@registry) do |f| %>
<% if @registry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@registry.errors.count, "error") %> prohibited this registry from    
being saved:</h2>

  <ul>
  <% @registry.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>
<% end %>


<%= f.label :due_date %><br />
<%= f.date_select :due_date, :rows => 5 %>


<%= f.label :theme %><br />
<%= f.text_field :theme, :class => 'field2' %>

<div class="field1">
<%= f.label :gender %><br />
<%= f.text_field :gender %>
</div>

<div class="field1">
<%= f.fields_for :presents do |builder| %>
<%= render 'present_fields', f: builder %>
<% end %>
</div>

<%= link_to_add_fields "Add Presents", f, :presents %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>

礼物字段:

<div class="field1">
<table>
<tr> 
<td> <%= f.label :type, "Present Type" %> </td>
<td> <%= f.text_field :type, :class => 'field2' %> </td>
<td> <%= f.label :Quantity, "Quantity" %> </td>
<td> <%= f.number_field :quantity, :class => 'field3' %> </td>
<td> <%= f.label :color, "Color" %> </td>
<td> <%= f.text_field :color, :class => 'field2' %> </td>
<td> <%= f.label :brand, "Brand" %> </td>
<td> <%= f.text_field :brand, :class => 'field2' %> </td>
<td> <%= f.link_to_remove "Remove this present" %></td>
</tr>
</table>
</div>

显示页面:<% provide(:title, 'My Party and Present Whishes') %> <%= notice %>

<p> Baby & Party Details: </p></br>
<li><p> Due date: </p> <%= @registry.due_date %></li></br>
<li><p> Party Theme: </p><%= @registry.theme %></li></br>
<li><p> Gender: </p><%= @registry.gender %></li></br>

<p> Presents Registry: </p></br>
<li>

<% @registry.presents.each do |registry| %>

<%= registry.type %>
<%= registry.quantity %>
<%= registry.color %>
<%= registry.brand %>

</li>

<% end %>

</br>
</br>
<%= link_to 'Edit', edit_registry_path(@registry) %>
<%= link_to 'Back', registries_path %>
4

1 回答 1

1
<li>

<% @registry.presents.each do |registry| %>

这些线不应该倒置吗?

<% @registry.presents.each do |registry| %>
<li>
于 2012-06-13T08:52:17.953 回答