<p>I have a div tag in the view that I'd like to update with a graph that I generate via Gruff.</p>

<p>I have the following controller action which does this at the end</p>

<pre><code>send_data g.to_blob, :disposition=&gt;'inline', :type=&gt;'image/png', :filename=&gt;'top_n.pdf'
</code></pre>

<p>Now if I directly invoke this action, I can see the graph. (More details <a href="http://madcoderspeak.blogspot.com/2008/12/graphs-in-ruby-on-rails.html" rel="nofollow noreferrer">here</a> if reqd.)</p>

<p>If I add a <code>link_to_remote_tag</code> that calls the above action via AJAX passing in specific input, generates this graph and tries to update a placeholder div tag... I see gibberish. </p>

<p>I think I can write the graph to a png file with <code>g.write(filename.png)</code> how do I embed the graph within the div tag in the view at run-time?</p>

In your link_to_remote tag just set :complete to something like this:
```
```
:complete => "updateImg(id_of_div, request.responseText)"
```
```
And write a JS function:
```
```
function updateImg(id, img)
{
  $(id).innerHTML = '<img src="' + img + '" />';
}
```
```
Where id_of_div is the id of the div when you want to show de image.
The request.responseText var come from the request of the AJAX call, I mean, when your code writes the png file with the graph, finish the method returning the path to this new png (render :text => path_to_new_image ); then, use this request variable in the :complete.