On Mar 11, 2010, at 6:04 PM, Adam Ziemba wrote:
Anyone not familiar with Google Charts, it's simple, a PNG image is
produced by a configured URL. E.g. follow the link:
http://chart.apis.google.com/chart?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0
:|Sun|Mon|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12
You'll see a chart that is a PNG image.
Okay so I need to save one of these to a file. I tried using Rails
"render" action, treating the URL as if it were a web page... I
might be
WAY off but I figure what I need is something like this:
File.open( "chart.png", "w" ) do |the_file|
the_file.puts render(:url =>
"http://chart.apis.google.com/chart?cht=bvg&chbh=a&chd=s:vttusty&chs=500x300&chxt=x,y&chxl=0
:|ELECTRICAL|BUMPER_PINTLEH|Tue|Wed|Thu|Fri|Sat|1:|0|2|4|6|8|10|12")
end
Basically I need to store the contents of what is produced by the
image
at that really long Google Charts URL shown above.
I apologize for my newbieness, and thank you for all the help!
Look at open-uri (require 'open-uri')
open('http://chart....') do |chart|
File.open('chart.png', 'w') {|f| f.write chart.read }
end
-Rob
Rob Biedenharn http://agileconsultingllc.com
[email protected]
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.