Gruff send_data


#1

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


#2

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


#3

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

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
Sent from the RubyOnRails Users mailing list archive at Nabble.com.


#4

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


#5

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


#6

On 4/9/07, Oliver 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.


#7

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
Sent from the RubyOnRails Users mailing list archive at Nabble.com.