0

我有一张包含许多发票行的发票。在编辑时,当单击发票行的删除按钮时,我使用 javascript 将隐藏的 _destroy 字段设置为值 1。提交后,它应该删除项目。它正在工作,但今天它随机停止了。

以下是传入的参数:

Parameters: {
"recycler_invoice"=>{
  "number"=>"IT10059",
  "customer_id"=>"1",
  "date_entered"=>"10/04/2013",
  "gold_spot_price_paid"=>"1248.12",
  "silver_spot_price_paid"=>"22.46",
  "platinum_spot_price_paid"=>"1206.13",
  "refine_fee_percentage"=>"5.0", 
  "consulting_fee_percentage"=>"3.0",
  "verify_fee_percentage"=>"2.0",               
  "recycler_invoice_lines_attributes"=>{
   "0"=>{"denomination_id"=>"11", "quantity"=>"315.767", "_destroy"=>"false", "id"=>"1023"},
   "1"=>{"denomination_id"=>"7", "quantity"=>"78.466", "_destroy"=>"false", "id"=>"1024"}, 
   "2"=>{"denomination_id"=>"1", "quantity"=>"1.174", "_destroy"=>"false", "id"=>"1025"}, 
   "3"=>{"denomination_id"=>"2", "quantity"=>"7.46", "_destroy"=>"false", "id"=>"1026"}, 
   "4"=>{"denomination_id"=>"9", "quantity"=>"28.909", "_destroy"=>"false", "id"=>"1027"}, 
   "5"=>{"denomination_id"=>"10", "quantity"=>"9.629", "_destroy"=>"false", "id"=>"1028"}, 
   "6"=>{"denomination_id"=>"13", "quantity"=>"19.77", "_destroy"=>"false", "id"=>"1029"}, 
   "7"=>{"denomination_id"=>"14", "quantity"=>"5.83", "_destroy"=>"false", "id"=>"1030"}, 
   "8"=>{"denomination_id"=>"22", "quantity"=>"240.37", "_destroy"=>"1", "id"=>"1031"}}},
"commit"=>"Submit",
"id"=>"9"}

如您所见,我要删除的一行的 _destroy 为 1。

这是我的更新代码......非常简单:

def update
    @recycler_invoice = RecyclerInvoice.find(params[:id])

    respond_to do |format|
      if @recycler_invoice.update_attributes(params[:recycler_invoice])
        format.html { redirect_to @recycler_invoice, notice: 'Recycler invoice was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @recycler_invoice.errors, status: :unprocessable_entity }
      end
    end
  end
4

1 回答 1

1

我猜在你的 RecyclerInvoice 中你已经添加了 accept_nested_attributes_for :recycler_invoice_lines,如果是这样,那么你可能忘记添加选项 allow_destroy: true 了。

于 2013-04-10T22:18:12.557 回答