新手问题 请教下 send_file 的问题!

liuyang_1991 · August 25, 2017 · Last by liuyang_1991 replied at August 26, 2017 · 1735 hits
def download_contract
  @order = Order.find(params[:id])
    send_file "http://localhost:3000#{current_user.avatar.url}" and return
end
<a class="odpp-download" href="<%= download_contract_member_user_order_path(current_user,order) %>">下载</a>

整个项目的权限我都给了777, 图片路径放到url地址上也能正常显示!
请问给为这是什么情况啊?
我需要改哪里?
谢谢!
2 Floor has deleted

这里楼主应该搞错了一个基础问题,send_file 是需要传入一个本地磁盘的路径,然后拿到目标文件的 File IO 对象,然后转交给前端的 web server(如 nginx)用 X-Accel-Redirect header 的方式返回给浏览器并指导浏览器下载的。

如果楼主想返回一个 url,应该用 redirect_to

send_file 是发送文件内容啊。你硬盘上哪有 http 这文件。

liuyang_1991 closed this topic. 04 Sep 09:07
You need to Sign in before reply, if you don't have an account, please Sign up first.