Ruby on rails 为什么更新表单会删除模型中的字段

Ruby on rails 为什么更新表单会删除模型中的字段,ruby-on-rails,controller,Ruby On Rails,Controller,我有一张叫做比尔的表格,上面有不同的名字。表单设置为,如果没有账单,则有一个占位符,但如果有账单,则显示账单名称。表格是这样的 bill.html.erb <%= form_for [:users, @bill], :validate => true do |f| %> <div class="row"> <div class="col-xs-6 form-group"> <% if bill.cell_phone.bla

我有一张叫做比尔的表格,上面有不同的名字。表单设置为,如果没有账单,则有一个占位符,但如果有账单,则显示账单名称。表格是这样的

bill.html.erb

<%= form_for [:users, @bill], :validate => true do |f| %>
  <div class="row">
    <div class="col-xs-6 form-group">
      <% if bill.cell_phone.blank?  %>
        <label> Cell Phone Company Name</label>
          <%= f.text_field :cell_phone, autofocus: true, class: 'form-control', placeholder: "Enter your cell phone company name as it shows on your bank statement" %>
     <% else %>
       <label>Current Cell Phone Company Name:</label>
          <%= bill.cell_phone %>
            <%= f.text_field :cell_phone, autofocus: true, class: 'form-control', placeholder: "Update your cell phone company name as it shows on your bank statement" %>
      <% end %>
    </div>
<div class="col-xs-6 form-group">
      <% if bill.gas_name.blank?  %>
        <label> Heating Gas Company Name</label>
          <%= f.text_field :gas_name, autofocus: true, class: 'form-control', placeholder: "Enter your heating gas company name as it shows on your bank statement" %>
      <% else %>
          <label> Current Heating Gas Company Name:</label>
            <%= bill.gas_name %>
            <%= f.text_field :gas_name, autofocus: true, class: 'form-control', placeholder: "Update your heating gas company name as it shows on your bank statement" %>
      <% end %>
    </div>
最后,这里是我的bills\u控制器更新方法(似乎工作正常)

-更新-

这是账单

def bill_params
    params.require(:bill).permit( :cell_phone, :gas_name, :rent_name, :electric_bill, :water_bill, :cable_bill, :insurance, :current_rent_pmt)
  end

“它会删除其他账单”--你是指同一用户的其他账单吗?使用当前用户。账单表示每个用户只有一张账单。或者
User
是否有多张:账单
,行应该是
当前用户。账单
?是的,每个用户有一张账单。换句话说,1个包含多个票据名称字段的票据模型。如果你看一下我在问题中提到的控制台,它显示用户向服务器发送带有新旧信息的账单,但在第3行或第4行,它只显示1或2个更新的项目。但是它应该保留那些没有更新的旧项目,那么它们之间有什么关系呢?用户
有一张:账单
?你也没有回答你的陈述“它抹掉了其他账单”——什么“其他账单”?你是说同一用户上的其他账单吗?关系是has_one:bill,为了回答这个问题,如果其他字段名没有放回表单中,它会将它们替换为nil。因此,例如,如果特定于用户的账单模型中有3个字段,并且输入为“A、B、C”,那么表单将显示“A、B和C”已经在模型中。如果我用“D”替换“C”来更新模型,那么它将更新,但是“A和B”所在的字段现在将为零,而C将被替换为“D”。啊,我看到了,我在SQL
更新中看到了它。您可以发布控制器的
账单参数
方法吗?
def update
    @user = current_user
    if current_user.bill.update_attributes(bill_params)
      TransAggregationWorker.perform_async(@user.id.to_s)
      redirect_to users_dashboard_path, :notice => "Payment Informaton Updated"
    else
      redirect_to users_dashboard_path, :notice => "Payment Information was not updated, please try again"
    end
  end
def bill_params
    params.require(:bill).permit( :cell_phone, :gas_name, :rent_name, :electric_bill, :water_bill, :cable_bill, :insurance, :current_rent_pmt)
  end