I have managed to force the download of a pdf to the user''s computer,
and make the link appear on a page rendered for the user. I cannot
figure out how to do both, however. You know "Your download will begin
shortly, if not click _here_"
Relevant controller code:
(this is solely for testing purposes, i will sanitize the path and such
later)
def test_render_first(path)
# send a url to the browser so I can give the user a link in case the
# download doesn''t happen
@download_url =
"http://#{@request.env[''SERVER_NAME'']}/#{path}"
render "file/download"
send_file(#{@request.env[''DOCUMENT_ROOT]''/#{path}",
:type => "application/pdf")
end
def test_send_first(path)
@download_url =
"http://#{@request.env[''SERVER_NAME'']}/#{path}"
send_file(#{@request.env[''DOCUMENT_ROOT]''/#{path}",
:type => "application/pdf")
render "file/download"
end
If I call test_render_first, the page renders, but the download never
happens. If i call test_send_first, the file is downloaded, but the page
never renders.
I can make it to happen with a meta refresh tag, but that is
unsatisfying because:
a) the pdf renders in the browser.
b) the user can''t go back to the site from there.
Thanks for your help,
Lee
*********************************
All that is gold does not glitter.
Not all those who wander are lost.
The old who are strong do not whither.
Deep roots are not touched by the frost.
-- J.R.R. Tolkein