Rails:send_file不会呈现页面或DoubleRender错误 [英] Rails: send_file never renders page or DoubleRender error
问题描述
所以我迷失在正确的事情上:
我有一个名为getapk.erb的页面,并在其控制器中有getfile代码。如果我遇到一个错误,我redirect_to pperror.erb
所以我不重定向到错误页面,但如果在页面上?
当你发送一个send_file的时候,所以显示'成功'页面和发送文件是两个单独的呈现。
我会让成功页面和文件下载两个单独的控制器操作,并显示一个链接
例如
def成功
#显示带有文件下载链接的html页面
结束
$ b $ def file_download
send_file #make确定你有:inline => false
end
然后你可以使用javascript来显示它们在同样的时间。
在success.erb的底部放置这样的事情,在成功页面呈现时自动调出下载对话框。
< script language =JavaScript>
window.location =<%= url_for:action =>file_download,:id => 'etc'%>;
< / script>
So I'm trying to trigger a download after a PayPal purchase. So the first way I did was on any error to redirect to an error page. This all works other than the results page never gets rendered after the fine is send. If I try to explicitly to render the page I get the DoubleRender error.
So I'm lost on what the correct things to do is:
I have a page called getapk.erb and have the getfile code in it's controller. If I encounter an error I redirect_to pperror.erb
So I not redirect to an error page, but an if on the page?
When you 'send_file' that is a render in it's self. So displaying a 'success' page and sending a file is two separate renders.
I would make the success page and file download two separate controller actions, and display a link to the file download on the success page.
e.g.
def success
#show html page with file download link
end
def file_download
send_file #make sure you have :inline => false
end
Then you could use javascript to make it appear they are rendering both at the same time.
At the bottom of your success.erb put somthing like this to bring up the download dialog box automatically on render of the success page.
<script language="JavaScript">
window.location=<%=url_for :action=>"file_download", :id => 'etc' %>;
</script>
这篇关于Rails:send_file不会呈现页面或DoubleRender错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!