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. <code> graph = GDChart::Graph.new ... graph.draw(f) send_file f.path, :type => "image/png", :disposition => "inline" </code> 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.
Hi, you might want to have a look at send_data, this sends a data stream to the client. The full description is at http://api.rubyonrails.org/classes/ActionController/Streaming.html . 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. > > <code> > graph = GDChart::Graph.new > ... > graph.draw(f) > send_file f.path, :type => "image/png", :disposition => "inline" > </code> > > 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.-- Posted via http://www.ruby-forum.com/.
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. On Sat, 10 Dec 2005, Nick Snels wrote:> Hi, > > you might want to have a look at send_data, this sends a data stream to > the client. The full description is at > http://api.rubyonrails.org/classes/ActionController/Streaming.html . > > 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. >> >> <code> >> graph = GDChart::Graph.new >> ... >> graph.draw(f) >> send_file f.path, :type => "image/png", :disposition => "inline" >> </code> >> >> 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 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.
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. On 12/10/05, Ken Bowley <rails-DESCn+CieYk@public.gmane.org> wrote:> 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. > > On Sat, 10 Dec 2005, Nick Snels wrote: > > > Hi, > > > > you might want to have a look at send_data, this sends a data stream to > > the client. The full description is at > > http://api.rubyonrails.org/classes/ActionController/Streaming.html . > > > > 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. > >> > >> <code> > >> graph = GDChart::Graph.new > >> ... > >> graph.draw(f) > >> send_file f.path, :type => "image/png", :disposition => "inline" > >> </code> > >> > >> 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. > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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: <code> ... def GraphGen graph = GDChart::Graph.new ... send_data graph.to_blob, :type => "image/png", :disposition => "inline", :filename => "graph.png" end </code> Keep in mind that specifying a filename here doesn''t actually save it locally. It simply suggests what the client should call it. Then from your view, simply do something like this: <code> ... <img src="<%= url_for :controller => ''CONTROLLER_NAME'', :action => ''GraphGen''%>"> </code> Best, Rob