Forum: Ruby on Rails how to redirect after sendfile?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bill W. (Guest)
on 2006-05-16 19:01
(Received via mailing list)
Greetings!

Is there a way to get RoR to redirect_to another action after doing a
sendfile?

My little app lets the user enter a bunch of data and then creates an
XML file from it.  I'm using sendfile to let the user download the XML
file.  Once they download the file I want to take them to a new view
that presents a logout button that will trigger a cleanup.  But it looks
like RoR treats the sendfile just like a render so the redirect after
the sendfile doesn't work.

Anybody know a way around this?

Thanks!
Bill
Carl-Johan K. (Guest)
on 2006-05-16 19:33
(Received via mailing list)
Redirect to the logout page first, and offer a link to the download
there. You might even load the link automatically after a few seconds
with javascript. That's what most download sites do.
Bill W. (Guest)
on 2006-05-16 20:21
(Received via mailing list)
Hi Carl,

Carl-Johan K. wrote:

> Redirect to the logout page first, and offer a link to the download there.

I really want to avoid having both the logout and download buttons on
the
same page / view if possible.  The users are presumed newbies and if
they
click the logout button first, they'll have lost everything they
entered.
The app 'walks them through' the data collection process with as few
choices
as possible other than enter data or don't enter data.

> You might even load the link automatically after a few seconds with
> javascript. That's what most download sites do.

Not sure what you're suggesting here.  Could you say more, please?  If
you're suggesting just sending them to the logout screen and then
invoking
sendfile via js, I don't see how that helps.  What's to prevent them
from
clicking the logout button if there's a delay in the save / download
dialog
appearing?

I really want to give them a chance to clean up the file /records
they've
created on the server rather than just waiting for their session to time
out.

Any other ideas?  Anybody else?

Thanks!
Bill
Rob K. (Guest)
on 2006-06-03 04:30
(Received via mailing list)
Hi Bill,
  To be honest, the only usable way I've ever gotten this to work is
to open a new window and send the download from there.  The fact that
Google and others do this makes me a little more comfortable, but on a
whole I still think it sucks.

-Rob
Julian 'Julik' Tarkhanov (Guest)
on 2006-06-03 07:19
(Received via mailing list)
On 3-jun-2006, at 2:29, Rob K. wrote:

>> sendfile via js, I don't see how that helps.  What's to prevent
>> them from
>> clicking the logout button if there's a delay in the save /
>> download dialog
>> appearing?

Forward the download into an iframe (and change the link to "Wait a
moment" - although I hate such meticulousness ;-))), and use a
JavaScript timeout to redirect the visitor to the logout page in the
parent frame.
There, stick a big button "Yes, I have downloaded my file and  you
can finish my session now".

--
Julian 'Julik' Tarkhanov
please send all personal mail to
me at julik.nl
Dave T. (Guest)
on 2006-06-03 20:38
(Received via mailing list)
Definately RoR treats the send_file just like any other render.  What I
do is redirect to a "downloading" page that describes the download will
happen and also has the logout button.  I prefer meta tags over
Javascript, and so I add this code to my application.rhtml layout
(because meta tags should go inside the HEAD element):

> <% if @set_download_refresh_meta %>
>	<meta http-equiv="refresh" content="2; URL=<%=@download.url%>" />
> <% end %>


Just incase the metatag doesn't work, I always add a comment like this:

> Your download should begin shortly. If it does not,
> click this link to manually download the file.

This is what I do on 1Passwd and it is how many sites like sourceforge
and download.com do it.

HTH.

On Tuesday, May 16, 2006, at 10:01 AM, Bill W. wrote:
>redirect after the sendfile doesn't work.
>
Cheers!
--Dave T.
http://1passwd.com - Password Manager + AutoFill for Mac OS X
http://devlists.com - Email list management
http://palmsphere.com - Apps for your hand-held
This topic is locked and can not be replied to.