The Rails way to download a file

I am looking for an example of how to download an xml file to a user’s
machine.

I have created a web page that allows the user to enter a file_name and
validates the field - using errors.add - but after a valid file_name has
been entered while the file does download properly, the web page is
never updated and it looks like there is still an error.

How do I send_data and redirect_to a status page?

Thanks.

Thanks!

i’m not sure you can - the download is the last thing you need to do in
order to make things work. so you show the status page, which then
redirects the browser to the download after it has loaded (via a
javascript redirect probably), so the user is left with the status page
on the screen and a download box.

something like
action:
def download
if params = correct
@download = true
else
@download = false
errors.add etc
end
end

and then in download.rhtml:

onload=“window.location=’<%=url_for(:controller=>“download”,:action=>“really_do_the_download”)%>’”
<%end%>>
<%if @download%>
Downloading…
<%else%>
There were errors!
<%end%>