Я пытаюсь вставить данные из поля зрения Ember, но я получаю следующее сообщение об ошибке:emberjs утверждение не удалось ошибка
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
вы можете поделиться формат вашего ответа JSON, для случая одного и нескольких записей? – intuitivepixel
Я получаю предупреждение как 'created successfully', но фактически не создан. Он просто пуст. Это было am, получая при просмотре консоли '{" refunds ": []}' – overflow
В консоли firefox URL-адрес: 'POST http: // localhost: 8080/refunds', а source is' {"refund": {"job_id": 691, «customer_id»: 424, «amount»: 11}} ' – overflow