Search code examples
ajaxhttppostember.jsput

Ember Data update POST when it should be PUT


I'm working on an Ember.js app. I have an update function, part of an ObjectController.

The function should save my updated model, however when I call save(); it sends a POST request not a PUT request. (Tested in Chrome.)

Why would that happen? How can I make sure a PUT request is sent for updates?

Here is my code:

customer = this.get('model');
customer.set('name', 'New name');
customer.save();

For extra reference, when I log the "dirtyType" with console.log( customer.get('dirtyType') ); it says "updated".

Any help very much appreciated!

UPDATE

I've adjusted the sample code above to make it clearer, I am NOT creating a new model and wanting to use PUT. I have an existing model that I need to update.


Solution

  • Thank you for all of your help guys, however I have found the issue and it is ridiculously silly.

    The API I have been using had a new flag "is_new" and that had been added to the model and was overwriting the "isNew" property.

    Causing Ember (and me) to get very confused.

    I've tweaked the API and all is good in the world!