在Rails控制器中send

编程入门 行业动态 更新时间:2024-10-09 19:17:42
在Rails控制器中send_file之后发生了什么?(What happend after send_file in Rails controller?)

在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 end

When 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.

更多推荐

本文发布于:2023-07-27 04:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   Rails   send

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!