Having finished the recipe details last night, I realized that I had no way of serving up the images stored in the CouchDB database. Something of a frightening realization, but it turns out to be as simple as:
get '/images/:permalink/:image' doThe
content_typeline specifies the content type as a JPEG image.
RestClient.getretrieves the document from the CouchDB database and serves up the output to the requesting client. The
:permalinkparameter is the URL of the recipe document itself. Accessing an attachment to that document is as simple as adding a slash and the name of the attachment. If the recipe's ID is
2008-07-21-spinachand the image filename is
spinach_pie_0004.jpg, then I can use the Sinatra resource to access the image at
Next up: deleting this and redoing it with a spec—mostly to handle not found errors.