The problem lies in the following code ("routes.rb").
post 'download_csr' do
file_name = File.dirname(__FILE__) + '/cert.csr'
File.open(file_name, 'w') do |f|
f.write params[:csr]
end
send_file file_name, :disposition => 'attachment'
erb :load_certificate, :locals => { :csr => 'cert.csr' }
end
The flow is this: the user clicks a button on a form, then a file is written and downloaded to local system, then it goes to another page (i.e., "load_certificate.erb").
However, what really happens is that after the file is downloaded, it doesn't go to the next page. But if I comment out "send_file", it will go to the next page. So how to address this? Thanks a lot!
One more thing: it would be good to make sure the file is actually downloaded before going to the next page (because when send_file pops out a window, the user can choose "cancel"). Some time-out mechanism may not work here.