Ruby on rails Rails 3.2用于添加而不是更新记录的字段

Ruby on rails Rails 3.2用于添加而不是更新记录的字段,ruby-on-rails,Ruby On Rails,我有一个Rails 3.2应用程序,其中字段_用于添加新记录,而不是更新现有记录 这在成本项目的模型中: has_many :costestimates, :dependent => :destroy accepts_nested_attributes_for :costestimates 这是表格的一部分: <%= simple_form_for @costproject do |f| %> ... <%= f.fields_for

我有一个Rails 3.2应用程序,其中字段_用于添加新记录,而不是更新现有记录

这在成本项目的模型中:

has_many :costestimates, :dependent => :destroy
accepts_nested_attributes_for :costestimates
这是表格的一部分:

   <%= simple_form_for @costproject do |f| %>
    ...
          <%= f.fields_for :costestimates do |builder| %>
              <fieldset>
                <% if builder.object.costproject.maintenance? %>
                    <% if builder.object.costcat.position.in?([3, 4, 9, 17, 18]) %>
                        <tr>
                          <td><%= builder.costcat.position %></td>
                          <td class="strongnowrap"><%= builder.costcat.category_name %></td>
                          <td><%= builder.input :amount, label: false, :input_html => {:style => 'width:100px'} %></td>
                          <% if builder.costcat.categorydesc != nil %>
                              <td>
                                <a rel="popover" data-content="<%= builder.costcat.categorydesc %>"><i class="icon-search"></i></a>
                              </td>
                          <% else %>
                              <td></td>
                          <% end %>
                          <td><%= builder.input :notes, label: false, :input_html => {:style => 'width:150px', :rows => 1} %></td>
                        </tr>
                    <% end %>
                <% else %>
                    <tr>
                      <td><%= builder.object.costcat.position %></td>
                      <td class="strongnowrap"><%= builder.object.costcat.category_name %></td>
                      <td><%= builder.input :amount, label: false, :input_html => {:style => 'width:100px'} %></td>
                      <% if builder.object.costcat.categorydesc != nil %>
                          <td>
                            <a rel="popover" data-content="<%= builder.object.costcat.categorydesc %>"><i class="icon-search"></i></a>
                          </td>
                      <% else %>
                          <td></td>
                      <% end %>
                      <td><%= builder.input :notes, label: false, :input_html => {:style => 'width:150px', :rows => 1} %></td>
                      <td><%= builder.object.id %></td>
                    </tr>
                <% end %>
              </fieldset>
          <% end %>

...
{:style=>'宽度:100px'}%>
{:style=>width:150px',:rows=>1}%>
{:style=>'宽度:100px'}%>
{:style=>width:150px',:rows=>1}%>

谢谢你的帮助

您必须将要编辑的资源提供给方法的
字段(作为
字段的第二个参数):

<%= f.fields_for :costestimates, @costproject.costestimates do |builder| %>

文件: (搜索“或要使用的集合”示例)


如果不指定要编辑的资源,则
字段将不包括包含资源id的
隐藏字段
,因此创建一个新记录而不是更新资源。

那么,您有什么问题吗?我还意识到,如果数据在数据表(jquery)中,它对我来说不起作用。