The URL for editing posts in your system looks like this:
http://wwwr.cs.unc.edu/emilyblog/posts/id.json
The URL should be submitted with an HTTP PUT request. In the above URL, id needs to be replaced with the numerical id of the blog post that you are trying to edit. This means that you need to put that value somewhere where you can get it. One technique that is used a lot is to construct an HTML id attribute for an element in your page associated with that resource that contains the number. You can't just use the number itself because HTML id attributes must be unique and there might be some other type of resource on your page that uses the same numerical id (for example, a comment).
The above URL needs to be submitted with two parameters: title and body which represent the updated title and body values. This is done in a similar way as the create post example. If successful, the responseJSON attribute of the Ajax.Response object provided to your onSuccess header will be an object the represents the updated blog post.
The code associated with this page retrieves all of the blog posts from your backend using the index URL and builds a little interface below for just the first entry. Obviously, your page will build an interface for all the entries, but I wanted to keep this example reasonably simple.
As part of that interface, I am constructing a <div> element and I give that element an HTML id attribute using the element's writeAttribute method. This is a method that you haven't seen before, but it is reasonably straightforward and you should be able to figure out what it is doing based on the code. The value of the id attribute is "post_id", where id is the post's numerical ID from the backend. That way, when I need that actual ID value, I can pick it out of the HTML id attribute using the JavaScript substring() method.
I associate a 'click' handler with the word "Edit" which replaces the original <div> with a new <div> that has a pre-filled form for editing the post (be sure to read through the code's comments to understand the way I did this). The handler uses the replace method of the element. This method returns the original element that was replaced. I store this original element in a property of the new element called original_div. It is not important exactly what that property is called (I just made it up and JavaScript properties spring into existence whenever you assign them for the first time), but it is important that we store it somewhere because we will need it to implement the handler associated with the "Cancel" button for restoring things as they were.
The handler associated with the "Update" button uses AJAX and a URL in the pattern shown above to actually do the edit. One thing to notice is that when I built the form, I put the post's numerical ID in a "hidden" input in the form so that I could get to it later. Another thing to notice is that I need to wait until the onSuccess callback for the AJAX call is fired before I can rebuild the interface.