I have a model appointment which has many tasks.
Creating a new appointment model which has tasks works fine with backbone. But when i try to update the model with the ids of different tasks it is not working.
I get the following error:
ActiveRecord::AssociationTypeMismatch: Task(#1192000) expected,
got ActiveSupport::HashWithIndifferentAccess(#2458300)
Parameters:
{"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"}
I have some idea that the problem is that there is tasks and task_ids in the request but I have no idea how to fix that in backbone.
My update method looks like this:
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;
},