【问题标题】:send_file not working - Ruby on Railssend_file 不工作 - Ruby on Rails
【发布时间】:2023-04-08 07:21:01
【问题描述】:

我在这里有这个动作:

def download
 send_file 'C:/Sites/solver/public/test.zip'
end

当我从我的 html 执行它时,没有任何反应,也没有下载任何内容。

但这是它产生的日志:

Started POST "/ssh/download" for 127.0.0.1 at 2014-04-03 11:06:17 -0400
Processing by SshController#download as */*
Sent file C:/Sites/solver/public/test.zip (0.0ms)
Completed 200 OK in 5ms (ActiveRecord: 0.0ms)

任何人都可以帮助我了解缺少什么?

谢谢!

【问题讨论】:

  • 试试send_file '/public/test.zip'
  • 你怎么称呼那个动作(下载)?我假设您正在建立一个链接?发布该代码可能会有所帮助。
  • Windows 不使用 \ 来分隔文件路径,而不是 /?
  • BroiStatse,你的方法给了我一个 MissingFile : cannot read file /public/test.zip 错误。
  • 如果我使用 windows 的 \ 它会给我 MissingFile 错误

标签: ruby-on-rails ruby sendfile


【解决方案1】:

在您看来,添加一个download 选项,例如:

link_to 'Download', download_path(id), download: "file"

【讨论】:

    猜你喜欢
    • 2014-01-05
    • 2012-01-29
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多