use*_*562 3 ruby-on-rails sendfile ruby-on-rails-4
有人可以告诉我如何下载文件send_file?
我image.jpg里面有一个文件app/assets/images.我在我的控制器中试过这个:
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
Run Code Online (Sandbox Code Playgroud)
对于每条路径,它说:
ActionController::MissingFile in HomeController#download
Cannot read file 'some_path'
Run Code Online (Sandbox Code Playgroud)
这可能是个问题?谢谢!
尝试:
IMAGES_PATH = File.join(Rails.root, "public", "images")
def download
send_file(File.join(IMAGES_PATH, "image.jpg"))
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19866 次 |
| 最近记录: |