# Gruff send\_data

**URL:** <https://www.ruby-forum.com/t/gruff-send-data/91489>\
**Category:** Rails\
**Created:** [April 9, 2007, 7:02pm UTC](https://www.ruby-forum.com/t/gruff-send-data/91489 "2007-04-09T19:02:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 9, 2007, 7:02pm UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/1 "2007-04-09T19:02:17Z")

</div>

Hi,

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

send\_data(g.to\_blob,  
: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.

Oliver

---

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 9, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/2 "2007-04-09T21:10:34Z")

</div>

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.

Shane  
[http://shanesbrain.net](http://shanesbrain.net)

---

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 9, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/3 "2007-04-09T21:43:42Z")

</div>

You seem to have everything right except the image\_tag:

Try:

image\_tag(url\_for(:controller =\> ‘my\_gruff\_controller’, :action =\>  
‘my\_gruff\_action’))

What you’re trying to achieve is:

[http://mydomain.com/my\_gruff\_controller/my\_gruff\_action](http://mydomain.com/my_gruff_controller/my_gruff_action)

Does this make sense?

Oliver-23 wrote:

> ```
> :type => 'image/png',
> 
> ```
> 
> Any idea?
> 
> Thanks in advance.
> 
> Oliver
> 
> >

–  
View this message in context:  
[http://www.nabble.com/gruff-send\_data-tf3548362.html#a9907760](http://www.nabble.com/gruff-send_data-tf3548362.html#a9907760)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 9, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/4 "2007-04-09T21:49:43Z")

</div>

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 …

Oliver

---

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 9, 2007, 11:13pm UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/5 "2007-04-09T23:13:54Z")

</div>

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

 section? … I am not  
so sure anymore

\<%= periodically\_call\_remote(  
:update =\> “show\_graph”,  
:frequency =\> 5,  
:url =\> { :action =\> :gruff\_report})  
%\>

 

Oliver

---

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 10, 2007, 12:20am UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/6 "2007-04-10T00:20:04Z")

</div>

On 4/9/07, Oliver [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> :filename => "gruff.png")
> 
> ```
> 
> Any idea?
> 
> Thanks in advance.
> 
> Oliver

I used respond\_to to do this:

in the controller something like:

respond\_to do |format|  
format.html  
format.png do  
send\_data(g.to\_blob,  
:disposition =\> ‘inline’,  
:type =\> ‘image/png’,  
:filename =\> “gruff.png”)  
end

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 D.

---

<div class="post-metadata">

**Author:** ![oliver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@oliver](https://www.ruby-forum.com/u/oliver)\
**Post date:** [April 10, 2007, 4:16am UTC](https://www.ruby-forum.com/t/gruff-send-data/91489/7 "2007-04-10T04:16:21Z")

</div>

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:

> ```
> :url => { :action => :gruff_report})
> 
> ```
> 
> > > ```
> > > :type => 'image/png',
> > > 
> > > ```
> > > 
> > > Any idea?
> 
> >

–  
View this message in context:  
[http://www.nabble.com/gruff-send\_data-tf3548362.html#a9912883](http://www.nabble.com/gruff-send_data-tf3548362.html#a9912883)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
