我有一個模型約會有很多任務。主幹更新嵌套集合與ID。 (Rails後端)
創建一個新的任務模型,其中任務與骨幹工作正常。但是,當我嘗試更新不同任務的ID的模型它不工作。
我收到以下錯誤:
ActiveRecord::AssociationTypeMismatch: Task(#1192000) expected,
got ActiveSupport::HashWithIndifferentAccess(#2458300)
參數:
{"appointment"=>
{"id"=>"36",
"customer_id"=>"19",
"employee_id"=>"10",
"done"=>"",
"notes"=>"",
"starts_at"=>"2012-09-05 13:00:00 +0200",
"ends_at"=>"2012-09-05 14:30:00 +0200",
"bookingtype"=>"",
"tasks"=>
"[{\"created_at\"=>\"2012-09-04T13:37:17+02:00\",
\"duration\"=>\"60\", \"id\"=>\"12\",
\"task_category_id\"=>\"5\", \"updated_at\"=>\"2012-09-04T13:46:13+02:00\"}]",
"appointment"=>"",
"task_ids"=>"[\"12\"]"},
"action"=>"update",
"controller"=>"appointments",
"id"=>"36"}
我有一些想法,問題是,有在請求任務和task_ids,但我不知道如何解決這個問題。
我更新的方法是這樣的:
save: function() {
var self = this;
var tasks = [];
$("input:checked").each(function() {
tasks.push($(this).val());
});
this.model.save({starts_at: this.$('#appointment_starts_at_modal').val(), employee_id: this.$('#employeeSelect').val(), customer_id: this.$('#customerSelect').val(),
"starts_at(5i)": this.$('#appointment_starts_at_5i_modal').val() ,
"ends_at(5i)": this.$('#appointment_ends_at_5i_modal').val(), task_ids: tasks}, {
success: function(model, resp) {
self.model = model;
self.close();
},
error: function() {
//new App.Views.Error();
}
});
return false;
},