Forum: Ruby on Rails gruff send_data

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0c1d26989fe0a2eea6daf6cdb5c7484b?d=identicon&s=25 Oliver (Guest)
on 2007-04-09 19:02
(Received via mailing list)
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
363548d0cfaaa4bab88747f31ad49c02?d=identicon&s=25 Shane Vitarana (Guest)
on 2007-04-09 21:10
(Received via mailing list)
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
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2007-04-09 21:43
(Received via mailing list)
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.ht...
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
0c1d26989fe0a2eea6daf6cdb5c7484b?d=identicon&s=25 Oliver (Guest)
on 2007-04-09 21:49
(Received via mailing list)
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
0c1d26989fe0a2eea6daf6cdb5c7484b?d=identicon&s=25 Oliver (Guest)
on 2007-04-09 23:13
(Received via mailing list)
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>

Oliver
C6858f4b8ec263c8c3c58759494e926a?d=identicon&s=25 Andy Delcambre (Guest)
on 2007-04-10 00:20
(Received via mailing list)
On 4/9/07, Oliver <fwang2@gmail.com> 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 Delcambre
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2007-04-10 04:16
(Received via mailing list)
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.ht...
Sent from the RubyOnRails Users mailing list archive at Nabble.com.
This topic is locked and can not be replied to.