在index视图中,有一个下载文件的链接:
<%= link_to filename, listing_download_path(:file => filename) %>在控制器中:
def download pathname = File.join(USER_FOLDER, params[:file]) if File.file?(pathname) send_file pathname end end end当用户单击下载时,将显示文件下载弹出窗口。 文件下载后会发生什么? 铁轨只是坐在那里再做什么? 如果我删除send_file行,将呈现dwonload.html.erb 。 send_file是否跳过视图呈现?
如果我想要显示“你已下载...”这样的内容怎么办?
In the index view, there is a link to download file:
<%= link_to filename, listing_download_path(:file => filename) %>In the controller:
def download pathname = File.join(USER_FOLDER, params[:file]) if File.file?(pathname) send_file pathname end end endWhen the user click download, a file download popup is shown. What's happen after the file is downloaded? Does rails just sit there and do nothing more? If I delete the send_file line, dwonload.html.erb will be rendered. Does send_file skip view rendering?
What if I want to show soemthing like "You have downloaded ..."?
最满意答案
send_file是一个渲染本身。 您可以使用此问题中提出的方法:
Rails:send_file永远不会呈现页面或DoubleRender错误
基本上,您的下载链接将发送到“成功”视图,您可以从中自动调用下载文件方法。
The send_file is a render itself. You could use the approach proposed in this question:
Rails: send_file never renders page or DoubleRender error
Basically your download link will send to a "success" view, from which you call the download file method automatically.
更多推荐
发布评论