fieldsjustin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 23:13 UTC
Can''t download files with send_data or send_file
I have a form_remote_tag that calls a method to print out a csv file for download. If I tell the form_remote_tag to update a div the data comes up in that div, but otherwise I can''t get the browser to acknowledge the sent file.>From view:<%= form_remote_tag :url => {:action => "csv_dump" }%> <%= submit_tag "Download Complete List" ,:name => "csv"%> <%= end_form_tag %>>From controller:def csv_dump @assignments = Assignment.find(:all) report = StringIO.new CSV::Writer.generate(report, '','') do |csv| csv << [''ID'', ''ExpoCode'',''Project'', ''CurrentStatus'',''AssignedTo'',''DataContact'', ''Action'',''Parameter'', ''Priority'', ''Deadline'',''LastChanged'', ''Notes'',''History''] @assignments.each do |task| csv << [task.id, task.ExpoCode, task.project, task.current_status, task.cchdo_contact, task.data_contact, task.action, task.parameter, task.priority, task.deadline, task.changed, task.notes, task.history] end end report.rewind send_data(report.read,:type => ''text/csv; charset=iso-8859-1; header=present'',:filename => ''report.csv'',:disposition => ''attachment'') #send_file("/Users/Shared/cchdo_watershed/public/whp_atlas/ pacific_index.html",:type => ''text'',:stream => "false",:disposition => ''attachment'') end --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Jun-08 15:10 UTC
Re: Can''t download files with send_data or send_file
fieldsjustin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> I have a form_remote_tag that calls a method to print out a csv file > for download. If I tell the form_remote_tag to update a div the data > comes up in that div, but otherwise I can''t get the browser to > acknowledge the sent file. > >>From view: > <%= form_remote_tag :url => {:action => "csv_dump" }%> > <%= submit_tag "Download Complete List" ,:name => "csv"%> > <%= end_form_tag %>Make the form a non-AJAX form, use submit_to_remote to trigger the AJAX call to update the div, and use an ordinary submit tag to trigger the CSV send. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
fieldsjustin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-09 18:10 UTC
Re: Can''t download files with send_data or send_file
Thanks! That fixed things right up. On Jun 8, 11:10 am, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> fieldsjus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > I have a form_remote_tag that calls a method to print out a csv file > > for download. If I tell the form_remote_tag to update a div the data > > comes up in that div, but otherwise I can''t get the browser to > > acknowledge the sent file. > > >>From view: > > <%= form_remote_tag :url => {:action => "csv_dump" }%> > > <%= submit_tag "Download Complete List" ,:name => "csv"%> > > <%= end_form_tag %> > > Make the form a non-AJAX form, use submit_to_remote to trigger > the AJAX call to update the div, and use an ordinary submit tag > to trigger the CSV send. > > -- > We develop, watch us RoR, in numbers too big to ignore.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I tried the same in my code. But always the browser is getting only the action name itself as the filename and it says it cannot find the file. Here is the code snippets from my application. Controller code : @filepath = "C:/Rails application/smartime/public/excel/" @filename = "report8.xls" send_file(@filepath + @filename, :disposition => ''attachment'', :encoding => ''utf8'', :type => ''application/octet-stream'') View code: <% form_tag({ :action => :exportToExcel })do %> <td width="35%" height="25%" align="left"> <%= submit_tag ''Export To Excel'' %> </td> <%end%> When I click on the "Export to excel button", the file is created in the server. The browser shows the file download window. But it shows the file name as "exportToExcel". When I click on save it shows error message "Internet explorer cannot download exportToExcelfrom localhost". I am running the server in localhost. What is missing in the code I am using? Thanks in advance. fieldsjustin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Thanks! That fixed things right up. > > On Jun 8, 11:10 am, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote: > > fieldsjus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > I have a form_remote_tag that calls a method to print out a csv file > > > for download. If I tell the form_remote_tag to update a div the data > > > comes up in that div, but otherwise I can''t get the browser to > > > acknowledge the sent file. > > > > >>From view: > > > <%= form_remote_tag :url => {:action => "csv_dump" }%> > > > <%= submit_tag "Download Complete List" ,:name => "csv"%> > > > <%= end_form_tag %> > > > > Make the form a non-AJAX form, use submit_to_remote to trigger > > the AJAX call to update the div, and use an ordinary submit tag > > to trigger the CSV send. > > > > -- > > We develop, watch us RoR, in numbers too big to ignore.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-19 17:42 UTC
Re: Can''t download files with send_data or send_file
On Jun 19, 2007, at 1:10 PM, Siva wrote:> I tried the same in my code. But always the browser is getting only > the action name itself as the filename and it says it cannot find the > file. Here is the code snippets from my application. > > Controller code : > > @filepath = "C:/Rails application/smartime/public/excel/" > @filename = "report8.xls" > send_file(@filepath + @filename, > :disposition => ''attachment'', > :encoding => ''utf8'', > :type => ''application/octet-stream'',:filename => @filename> ) > > View code: > <% form_tag({ :action => :exportToExcel })do %> > <td width="35%" height="25%" align="left"> > <%= submit_tag ''Export To Excel'' %> > </td> > <%end%> > > When I click on the "Export to excel button", the file is created in > the server. The browser shows the file download window. But it shows > the file name as "exportToExcel". When I click on save it shows error > message "Internet explorer cannot download exportToExcelfrom > localhost". I am running the server in localhost. > > What is missing in the code I am using? > > Thanks in advance. > > fieldsjustin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> Thanks! That fixed things right up. >> >> On Jun 8, 11:10 am, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote: >>> fieldsjus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >>>> I have a form_remote_tag that calls a method to print out a csv >>>> file >>>> for download. If I tell the form_remote_tag to update a div the >>>> data >>>> comes up in that div, but otherwise I can''t get the browser to >>>> acknowledge the sent file. >>> >>>>> From view: >>>> <%= form_remote_tag :url => {:action => "csv_dump" }%> >>>> <%= submit_tag "Download Complete List" ,:name => "csv"%> >>>> <%= end_form_tag %> >>> >>> Make the form a non-AJAX form, use submit_to_remote to trigger >>> the AJAX call to update the div, and use an ordinary submit tag >>> to trigger the CSV send. >>> >>> -- >>> We develop, watch us RoR, in numbers too big to ignore.Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello, I have a similar problem and I am using select helper alongwith observe_field. Any clues are greatly appreciated. View: <%= select(''temp_data'',''choose'', ["Spreadsheet","Flat Spreadsheet","Pipe-delimited","Flat Pipe-delimited"], {:selected => nil},{:id => "report_download_select"}) %> <%= observe_field ''report_download_select'', :url => {:action => ''generate_report'', :id => @dataset}, :on => ''focus'', :with => "''report_download_select='' + $F(''report_download_select'')", :update => {} %> Controller: ... ... send_data(output.read, :type => content_type, :filename => filename, :encoding => ''utf8'') Rob Biedenharn wrote:> On Jun 19, 2007, at 1:10 PM, Siva wrote: >> :encoding => ''utf8'', >> :type => ''application/octet-stream'', > > :filename => @filename > >> the server. The browser shows the file download window. But it shows >>> >>>>> <%= form_remote_tag :url => {:action => "csv_dump" }%> >>>>> <%= submit_tag "Download Complete List" ,:name => "csv"%> >>>>> <%= end_form_tag %> >>>> >>>> Make the form a non-AJAX form, use submit_to_remote to trigger >>>> the AJAX call to update the div, and use an ordinary submit tag >>>> to trigger the CSV send. >>>> >>>> -- >>>> We develop, watch us RoR, in numbers too big to ignore. > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
for filename specify your filename directly with filepath for e.g @filepath = "C:/Rails application/smartime/public/excel/"+"report8.xls" and then pass this variable for filename It might work Siva wrote:> I tried the same in my code. But always the browser is getting only > the action name itself as the filename and it says it cannot find the > file. Here is the code snippets from my application. > > Controller code : > > @filepath = "C:/Rails application/smartime/public/excel/" > @filename = "report8.xls" > send_file(@filepath + @filename, > :disposition => ''attachment'', > :encoding => ''utf8'', > :type => ''application/octet-stream'') > > View code: > <% form_tag({ :action => :exportToExcel })do %> > <td width="35%" height="25%" align="left"> > <%= submit_tag ''Export To Excel'' %> > </td> > <%end%> > > When I click on the "Export to excel button", the file is created in > the server. The browser shows the file download window. But it shows > the file name as "exportToExcel". When I click on save it shows error > message "Internet explorer cannot download exportToExcelfrom > localhost". I am running the server in localhost. > > What is missing in the code I am using? > > Thanks in advance.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---