Your example should have used send_file, as data was created on the filesystem. As for your other question: send_data can send generic buffers without having to save anything on the disc: send_data buffer will send content of buffer. Hope it helped, Zsombor -- http://deezsombor.blogspot.com
Gregg Pollack wrote:> Only problem is when it attempts the File download, IE always complains > "Cannot download export from localhost. The requested site is either > unavailable or cannot be found. Please try again later."What do other browsers (or specifically, Mozilla Firefox) tell you? The following Firefox extension may give some insight into what''s happening... http://livehttpheaders.mozdev.org/ ... and should give you a clue where to start looking. Feel free to email me the log output off-list, and I''ll see if I can help you. ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
After reading around the internet and the archives, I came up with the following code to export to CSV. require ''csv'' def export CSV.open(RAILS_ROOT + "public/export.csv", ''wb'') do |writer| writer << [''r1c1'', ''r1c2''] writer << [''r2c1'', ''r2c2''] writer << [nil, nil] end send_data RAILS_ROOT + "public/export.csv", :type => ''application/csv'' end As you can see, this code generates a CSV file, saves it to the hard drive, and then send_data attempts to send the created file to the user. Only problem is when it attempts the File download, IE always complains "Cannot download export from localhost. The requested site is either unavailable or cannot be found. Please try again later." The valid exported file is being created, I can open it from my file manager, so why is it not sending properly? Can anyone tell me what''s going wrong? And is there anyway to send data WITHOUT having to save the file to disk? Using CSV to create a buffer and send that perhaps? Thanks in advance, Gregg Pollack
Zsombor, I have tried both send_data and send_file. They both render the same error I listed. The only difference is that send_file takes about 10 seconds for the server to respond, where as send_data is instantaneous. How would I use rail''s CSV tools to create a buffer which I could then send? This is not clear. Thanks for the response though, -Gregg -----Original Message----- From: Dee Zsombor [mailto:dee.zsombor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] Sent: Monday, July 25, 2005 9:47 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Export to Excel Help Your example should have used send_file, as data was created on the filesystem. As for your other question: send_data can send generic buffers without having to save anything on the disc: send_data buffer will send content of buffer. Hope it helped, Zsombor -- http://deezsombor.blogspot.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I think that problem is with your setup, that is why you get the same error. Now send_data fails faster, as you are only sending a string instead of file content: i.e: RAILS_ROOT + "public/export.csv" BTW: this will generate CSV data directly to a string buffer instead file: require ''stringio'' require ''csv'' def export StringIO.open do |io| CSV::Writer.generate(io) do |writer| writer << [''r1c1'', ''r1c2''] writer << [''r2c1'', ''r2c2''] writer << [nil, nil] end send_data io.string, :filename => "my_data.csv" end end Zsombor On 7/25/05, Gregg Pollack <patched-i8bqrNpN1PPCXmymsgaQcQ@public.gmane.org> wrote:> Zsombor, > > I have tried both send_data and send_file. They both render the > same error I listed. The only difference is that send_file takes about 10 > seconds for the server to respond, where as send_data is instantaneous. > > How would I use rail''s CSV tools to create a buffer which I could > then send? This is not clear. > > Thanks for the response though, >-- http://deezsombor.blogspot.com