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.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-05-16 17: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
E24b2a1d71b7365186a934a09ee6f7c3?d=identicon&s=25 Carl-Johan Kihlbom (Guest)
on 2006-05-16 17: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.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-05-16 18:21
(Received via mailing list)
Hi Carl,

Carl-Johan Kihlbom 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
2a3be1d8227283eb4e1613ef631d78b8?d=identicon&s=25 Rob Kaufman (Guest)
on 2006-06-03 02: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
A2b2f4ee23989dc68529baef9cbddcd6?d=identicon&s=25 Julian 'Julik' Tarkhanov (Guest)
on 2006-06-03 05:19
(Received via mailing list)
On 3-jun-2006, at 2:29, Rob Kaufman 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
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Dave Teare (Guest)
on 2006-06-03 18: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 Walton wrote:
>redirect after the sendfile doesn't work.
>
Cheers!
--Dave Teare
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.