I am using BackboneJS and have a model object to update.
self.model.save(
{
urlRoot: +self.model.get("personId")+"/deactivate"
},
{
success: function (model){
self.showMessage('Person deactivated', true, true);
self.model.fetch();
},
error : function(){
$("#save", self.el).button("reset");
}
});
Now my REST method looks like
@PUT
@Path("{id}/deactivate")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public CompanyVO deactivatePerson(@PathParam("id") Long id, PersonVO personVO) {
return modifyPerson(id, personVO);
}
Is there an issue with how I am setting urlRoot to call the corresponding REST method?
What is the correct way to call the REST method and update the Person object?
The save method prototype is : model.save([attributes], [options])
The first parameter is attributes. Second one is options, such as url, success, error methods can be specified.
If you already have set all attributes of a model, then pass '[]' as first parameter to save i.e.
self.model.save([],{
urlRoot: +self.model.get("personId")+"/deactivate, //ensure protocol + domain name are added
success: function (model){
self.showMessage('Person deactivated', true, true);
self.model.fetch();
},
error : function(){
$("#save", self.el).button("reset");
}
});