0

ember のビューからデータを挿入しようとしていますが、次のエラー メッセージが表示されます。

Uncaught Error: assertion failed: Your server returned a hash with the key refunds but you have no mapping for it

これが私のコーディングで、誰でも修正できます。

私のハンドルバー

<form>
   <th>{{view Ember.TextField valueBinding="refund_amount" placeholder="Enter refund amount"}}</th>
   <td><button type="submit" class="btn btn-success complete-btn" {{action saveRefund}}>Refund</button></td>
</form>

私のjsモデル

Office.Refund = DS.Model.extend({
    job_id: DS.attr('number'),
    customer_id: DS.attr('number'),
    amount: DS.attr('number')
});

私のjsコントローラー

saveRefund: function() {
    var refund = Office.Refund.createRecord({
    job_id: this.get('id'),
    customer_id: this.get('customer.id'),
    amount: this.get('refund_amount')
  });
    this.get('store').commit();
    refund.on('didCreate',function() {
    alert('created successfully');
  });
}

ここに私のrefund_controller.rbがあります

  def index
    @refund = Thunderbolt::Refund.all
    respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @refund}
    end
  end
def new
    @refund = Refund.new
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @refund }
    end
  end

  def create
    refunds = params[:refund]
    @refund = Refund.new(job_id: refunds[:job_id], customer_id: refunds[:customer_id], amount: refunds[:amount])
    respond_to do |format|
      if @refund.save
        format.html { redirect_to @refund, notice: 'Refund successful.' }
        format.json { render json: @refund, status: :created, location: @refund }
      else
        format.html { render action: "new" }
        format.json { render json: @refund.errors, status: :unprocessable_entity }
      end
    end
  end

ここに私のrefund_serializer.rbがあります

  class RefundSerializer < ActiveModel::Serializer
    attributes :id, :job_id, :customer_id, :amount, :created_at, :updated_at
  end

これが私のrefund.rbモデルです

  class Refund < ActiveRecord::Base
    attr_accessible :id, :amount, :customer_id, :job_id, :created_at, :updated_at
  end
4

2 に答える 2