Reputation: 75
i m working on an app in rails that requires the following :
I 've searched the web and found that it is not possible to render and redirect at the same time for a given action , is there any ways around this issue ?
Upvotes: 1
Views: 2451
Reputation: 7366
send_data
using render, so you can't do anything after it in your controller.
To do this you have to use javascript:
Create a iframe on button click. (That will hold your download process).
Redirect the page on the iframe's close event.
You can also use a background job for download action but I haven't used it yet.
Upvotes: 0
Reputation: 638
You could send the user to a result page and add a meta tag to redirect the user to a download after x seconds.
<meta http-equiv="refresh" content="5; url=http://path_to/your/download.zip"/>
This is the approach you see at a lot of sites e.g. sourceforge.net (Your download will start after x seconds...)
Upvotes: 1