Question

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);
}

My question is there is some issue how I am setting urlRoot to call the corresponding REST method.

Please let me know the correct way so that I can call the REST method and update the Person object.

Was it helpful?

Solution

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");
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top