gruff send_data


for those with experience of Gruff module: suppose I want to send
image from server straight to the browser (as example on gruff web

            :disposition => 'inline',
            :type => 'image/png',
            :filename => "gruff.png")

the server seems sending this binary data ok, but I am having trouble
to display it properly:

I have tried

<%= link_to_image "gruff.png"%> or <%= image_tag "gruff.png" %>.
Neither works. The browser gives a bunch of binary encoding.

Any idea?

Thanks in advance.


I just write the file to the disk and serve up the image. i.e: g.write(filename), and then use the image tag helper in the view like you have done.


You seem to have everything right except the image_tag:


image_tag(url_for(:controller => 'my_gruff_controller', :action =>

What you're trying to achieve is:

Does this make sense?

Oliver-23 wrote:

Thanks for the reply. That is certainly one way to go about it. I was
able to write a file and read it properly.

Some issues with this approach: I have put this image into a a
periodic update section. Write it then read it make the refresh rather
obvious. I was hoping send_data will make it visually a little better,
but then I guess this might not be the "rails" way of doing this kind
of update ... So far, I think I didn't really find a GOOD way to give
you live update charting with gruff ...


Thanks - by coincidence, I also stumble onto this way of calling ...
I believe this will work under normal circumstances ... what if I am
calling it this way to update only this <div> section? ... I am not
so sure anymore

<%= periodically_call_remote(
    :update => "show_graph",
    :frequency => 5,
    :url => { :action => :gruff_report})

<div id="show_graph"> </div>


I used respond_to to do this:

in the controller something like:

respond_to do |format|
format.png do
           :disposition => 'inline',
           :type => 'image/png',
           :filename => "gruff.png")

then the route needs to have :controller/:action/:id.:format

then controller/action/id will give you the html (probably a page with
an img tag to the actual chart), and controller/action/id.png will
return the actual image.

Hope that helps,
Andy Delcambre

Presuming the 'gruff_report' action renders the correct html to fill the
'show_graph' element, you should be fine. Bear in mind that gruff graphs can
be a chunky download, so refreshing them every 5 seconds might be hard on
the server.

Oliver-23 wrote: