In my Rails app, I have a model called "Photo" and a PhotosController. As would be expected, I've RESTfully routed the URLs so that the URL "/photos" returns an HTML-rendered list of all photos (as thumbnails), and "/photos/foo" returns an HTML-rendered representation of the photo with the friendly_id of "foo". (I also do XML, JSON, and binary representations, but they're not relevant here.)
I want to make the list page show a subset of Photo thumbnails on initial load, and then dynamically add more thumbnails to my list via AJAX (specifically jQuery). I already have HTML that renders an individual photo list item (basically an <li><img>
) in the photos/index view. Since jQuery can inject HTML directly into the DOM, I figure that the best thing to do is extract the list-item code into a partial and then load that partial through AJAX into the list.
My question is: what's the best way to get the HTML out of the partial and into the DOM?
(I already have an idea for implementation; I'll post it as an answer to allow appropriate voting & commenting).