ruby-on-rails - send_file返回值

标签 ruby-on-rails ruby-on-rails-3

Rails 中的 send_file 方法有返回值吗?如果发送成功,我想做一件事,如果发送不成功,我想做另一件事。我查看了文档this link ,但没有找到任何相关内容。

最佳答案

不,无法通过 send_file 确认下载完成或成功。来自这个问题:Can we find out when a Paperclip download is complete? :

send_file creates the file and then passes a special header to tell the webserver telling it what to send. Rails doesn't actually send the file at all, it sets this header which tells the webserver to send the file but then returns immediately, and moves on to serve another request. To be able to track if the download completes you'd have to occupy your Rails application process sending the file and block until the user downloads it, instead of leaving that to the webserver (which is what its designed to do). This is super inefficient.

您也许可以在客户端上使用 cookie 和 JavaScript 执行某些操作。 看这个问题:Rails File Download And View Update - Howto?

关于ruby-on-rails - send_file返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13188117/

相关文章:

ruby-on-rails - 在所有 Rails 助手中将协议(protocol)更改为 https

ruby-on-rails-3 - 为什么 where 查询在 postgresql 中不起作用?

mysql - 迁移文件和架构

ruby-on-rails - 如何在 Rails 中创建图表?

ruby-on-rails - 回形针 gem 欺骗错误?

ruby-on-rails - 工作客户端在启动后几秒钟内停止

activerecord - 在Rails 3中的has_many:through关系中过滤子对象

ruby - 如何使用 link_to Ruby on rails 添加确认消息

python - Python 3000 上有没有像 RoR 这样的框架?

Ruby/Rails : accessing a variable inside a . 在我的实例变量数组上导致 Ruby 解释器崩溃