{"id":1486,"date":"2022-08-30T15:16:56","date_gmt":"2022-08-30T15:16:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/23\/emberjs-assertion-failed-error-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:56","modified_gmt":"2022-08-30T15:16:56","slug":"emberjs-assertion-failed-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/emberjs-assertion-failed-error-collection-of-common-programming-errors\/","title":{"rendered":"emberjs assertion failed error-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to insert data from ember&#8217;s view but am getting following error message:<\/p>\n<pre><code>Uncaught Error: assertion failed: Your server returned a hash with the key refunds but you have no mapping for it\n<\/code><\/pre>\n<p>and here is my coding can anyone correct it.<\/p>\n<p>My handlebar<\/p>\n<pre><code>\n   <\/code><\/pre>\n<th><code>{{view Ember.TextField valueBinding=\"refund_amount\" placeholder=\"Enter refund amount\"}}<\/code><\/th>\n<td><code>Refund<\/code><\/td>\n<p>My js model<\/p>\n<pre><code>Office.Refund = DS.Model.extend({\n    job_id: DS.attr('number'),\n    customer_id: DS.attr('number'),\n    amount: DS.attr('number')\n});\n<\/code><\/pre>\n<p>MY js controller<\/p>\n<pre><code>saveRefund: function() {\n    var refund = Office.Refund.createRecord({\n    job_id: this.get('id'),\n    customer_id: this.get('customer.id'),\n    amount: this.get('refund_amount')\n  });\n    this.get('store').commit();\n    refund.on('didCreate',function() {\n    alert('created successfully');\n  });\n}\n<\/code><\/pre>\n<p>Here is my refund_controller.rb<\/p>\n<pre><code>  def index\n    @refund = Thunderbolt::Refund.all\n    respond_to do |format|\n    format.html # index.html.erb\n    format.json { render json: @refund}\n    end\n  end\ndef new\n    @refund = Refund.new\n    respond_to do |format|\n      format.html # new.html.erb\n      format.json { render json: @refund }\n    end\n  end\n\n  def create\n    refunds = params[:refund]\n    @refund = Refund.new(job_id: refunds[:job_id], customer_id: refunds[:customer_id], amount: refunds[:amount])\n    respond_to do |format|\n      if @refund.save\n        format.html { redirect_to @refund, notice: 'Refund successful.' }\n        format.json { render json: @refund, status: :created, location: @refund }\n      else\n        format.html { render action: \"new\" }\n        format.json { render json: @refund.errors, status: :unprocessable_entity }\n      end\n    end\n  end\n<\/code><\/pre>\n<p>Here is my refund_serializer.rb<\/p>\n<pre><code>  class RefundSerializer &lt; ActiveModel::Serializer\n    attributes :id, :job_id, :customer_id, :amount, :created_at, :updated_at\n  end\n<\/code><\/pre>\n<p>Here is my refund.rb model<\/p>\n<pre><code>  class Refund &lt; ActiveRecord::Base\n    attr_accessible :id, :amount, :customer_id, :job_id, :created_at, :updated_at\n  end\n<\/code><\/pre>\n<ol>\n<li>\n<p>Solved this error by adding <code>resources :refunds<\/code> in <code>routes.rb<\/code> instead of<\/p>\n<pre><code>  get \"refunds\/index\"\n\n  get \"refunds\/new\"\n\n  get \"refunds\/edit\"\n\n  get \"refunds\/show\"\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Before the comments are getting to long I&#8217;ll try to explain it in an answer. When you post a new record to be saved, your backend should return the new record with an <code>id<\/code> set to it like:<\/p>\n<pre><code>{\n  \"refund\": {\n    \"id\": 123,\n    \"job_id\":691,\n    \"customer_id\":424,\n    \"amount\":1\n  }\n}\n<\/code><\/pre>\n<p>If <code>job_id<\/code> is your record&#8217;s primary key the you need to have a mapping for it in your <code>DS.RESTAdapter<\/code>, do you?<\/p>\n<p>Hope it helps.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-23 09:50:26. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am trying to insert data from ember&#8217;s view but am getting following error message: Uncaught Error: assertion failed: Your server returned a hash with the key refunds but you have no mapping for it and here is my coding can anyone correct it. My handlebar {{view Ember.TextField valueBinding=&#8221;refund_amount&#8221; placeholder=&#8221;Enter refund amount&#8221;}} Refund My js [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1486","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1486"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1486\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}