gpt4 book ai didi

ruby-on-rails - 如何使用send_file下载文件?

转载 作者:行者123 更新时间:2023-12-01 07:02:21 28 4
gpt4 key购买 nike

有人可以启发我如何使用 send_file 下载文件?

我有一个文件 image.jpgapp/assets/images .我在我的 Controller 中试过这个:

def download
send_file ("#{Rails.root}/public/images/image.jpg")
end

def download
send_file ("#{Rails.root}/assets/images/image.jpg")
end

def download
send_file ("#{Rails.root}/images/image.jpg")
end

def download
send_file ("/public/images/image.jpg")
end

def download
send_file ("/assets/public/images/image.jpg")
end

def download
send_file ("/assets/images/image.jpg")
end

对于每条路径,它说:
ActionController::MissingFile in HomeController#download
Cannot read file 'some_path'

这里可能有什么问题?谢谢!

最佳答案

尝试:

IMAGES_PATH = File.join(Rails.root, "public", "images")

def download
send_file(File.join(IMAGES_PATH, "image.jpg"))
end

关于ruby-on-rails - 如何使用send_file下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22002020/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com