I’m working on a project right now that is migrating a site to RoR
(originally written in Ruby… but not as easy to add features, hence
the
migration). The one sticking point is a 3d GDchart graph made using the
gdchart binding for ruby http://www.cozmixng.org/repos/ruby/gdchart/trunk/
The problem is that GDChart wants to output the file to a stream (a
file,
STDOUT, etc…). At the moment I have the image being saved to a file,
then using send_file. I would like to find a way to send the image
without saving to a tempfile first.
Any solutions on how to avoid using the file? I’m probably missing
something obvious here. Of course I’m open to other solutions that can
create nice looking 3d charts and graphs.
you might want to have a look at send_data, this sends a data stream to
the client. The full description is at ActionController::Streaming .
Kind regards,
Nick
rails wrote:
I’m working on a project right now that is migrating a site to RoR
(originally written in Ruby… but not as easy to add features, hence
the
migration). The one sticking point is a 3d GDchart graph made using the
gdchart binding for ruby http://www.cozmixng.org/repos/ruby/gdchart/trunk/
The problem is that GDChart wants to output the file to a stream (a
file,
STDOUT, etc…). At the moment I have the image being saved to a file,
then using send_file. I would like to find a way to send the image
without saving to a tempfile first.
Any solutions on how to avoid using the file? I’m probably missing
something obvious here. Of course I’m open to other solutions that can
create nice looking 3d charts and graphs.
I originally wanted to do this, but I couldn’t figure out how to make it
work. Honestly, I think I’m just missing something obvious. I know how
to make GDChart output to a file or to STDOUT or STDERR, but I can’t
figure out how to pipe this together with send_data to send the image.
I think I’m just missing something obvious. I know how
to make GDChart output to a file or to STDOUT or STDERR, but I can’t
figure out how to pipe this together with send_data to send the image.
From distant (perl w/GDChart) memory, try using graph.out(width, height, output,
type, data) instead…
It would be nice to use something along the lines:
send_data(:type => ‘img/png’, :disposition => ‘inline’) do |output|
graph.out(w, h, output, type, data)
end
but I haven’t got a rig setup to test this out right now, but not sure
if
send_data supports blocks.
In the controller for this action/view, create a new action, call it
GraphGen,
for instance. Let’s assume that the function call to render your graph
as a
binary blob is called “to_blob”. Then just do:
You can create a separate controller method with send_data at the end,
then in your rhtml just quote the URL of that method as the source of
a image tag.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.