0

I have this code:

var SotriesModel = can.Model.extend({
    findAll: 'GET /api/stories/',
    create: function(story) {
        console.log(story)
        return $.ajax({
            url: '/api/stories/',
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify(story)
        });
    },
    update : function(story) {
        console.log(story)
        return $.ajax({
            url: '/api/stories/',
            type: 'PUT',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify(story)
        });
    },
    destroy: 'DELETE /api/stories/{id}'
}, {});
var story = new SotriesModel({id:123123, name:"test"});
story.save();

What I expect from save is a PUT request with a JSON in payload, but what I get is just the id number:

123123
ramblinjan
  • 6,578
  • 3
  • 30
  • 38
nvcnvn
  • 4,991
  • 8
  • 49
  • 77

1 Answers1

0

The update method signature for using a function is can.Model.update: function(id, serialized) -> can.Deffered.

So as the first parameter you always get the id and as the second the serialized data.

Changing your update : function(story) {} to update : function(id, story) {} should solve the problem.

Daff
  • 43,734
  • 9
  • 106
  • 120