Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate_attributes operation not completed while using "serialize" or "accepts_nested_attributes_for" in rails one to many relation
    text
    copied!<p>controller update method</p> <pre><code>class InvoicesController &lt; ApplicationController def update @invoice = Invoice.find(params[:id]) respond_to do |format| if @invoice.update_attributes(params[:invoice]) format.html { redirect_to invoices_path } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @invoice.errors} end end end end </code></pre> <p>models</p> <p>invoice.rb</p> <pre><code>class Invoice &lt; ActiveRecord::Base has_many :invoice_line_items,:dependent =&gt; :destroy accepts_nested_attributes_for :invoice_line_items,:allow_destroy =&gt; true attr_accessible :invoice_dt, :invoice_no,:invoice_line_items_attributes,:amount_due,:tax1,:tax2,:tax3,:tax4,:tax5,:tax1_value,:tax2_value,:tax3_value,:tax4_value,:tax5_value attr_accessor :amount_due,:tax1,:tax2,:tax3,:tax4,:tax5,:tax1_value,:tax2_value,:tax3_value,:tax4_value,:tax5_value </code></pre> <p>invoice_line_item.rb</p> <pre><code>class InvoiceLineItem &lt; ActiveRecord::Base belongs_to :invoice attr_accessible :invoice_id, :item_description, :item_no, :quantity, :unit_price,:taxes,:tax1,:tax2,:tax3,:tax4,:tax5 attr_accessor :tax1,:tax2,:tax3,:tax4,:tax5 serialize :taxes, Hash before_validation :my_taxes def my_taxes debugger self.taxes = {"tax1" =&gt; self.tax1,"tax2" =&gt; self.tax2,"tax3" =&gt; self.tax3,"tax4" =&gt; self.tax4,"tax5" =&gt; self.tax5} end end </code></pre> <p>Issue generates while i try to update data. In update date i get all updated value while i checked it with debugger but its not save in database. I found one reason is "add_taxes" method which successfully called in create but not called in update operation. Also remember my "taxes" variable is serialize and i used accepted_nested_attributes _for.</p> <p>Can anyone please help me. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload