Save object to nested route

I have a document model which has many signatures. The idea is to sign the document using a userName and password.

I GET the document from /documents/:doumentId

In the document template I show an empty form with user and password input fields and a button.

When the user clicks the button a signDocument action is handled in the document’s controller, where I create a new signature object and save it.

However the POST message is sent to /signatures and not to do /document/:id/signatures.

My router is as follows:

Router.map(function() {
  this.route("document", { path: "/documents/:document_id" }, function() {
    this.route("signatures");
  });
});

The document and signatures are shown using the document template, I am not using the signatures template

What am I missing?

Are you using Ember Data?

David,

Yes, I am using Ember Data.

After some research I noticed that the way to go is sending the POST to /signatures and including the relationships info in the payload. Is this right?

Regards, Héctor

Yes, I’d say that is the more conventional RESTful approach. If you do want to change the URL when you create a record, you can modify it in the model’s adapter.

David.

The answer was in the Changing the URL for Certain Operations chapter in your Ember Data in the Wild book.

I was so confused that I did not realize that!

However I will use the plain /signatures path to keep things simple.

Thank you very much,

Héctor

1 Like