我有2个Rails应用程序,App1和App2。
App1包含指向App2中控制器操作的链接,后者又返回文件(下载),例如:
<%= link_to "Download Video", "http://app2/downloads/download_video", :target => "_bkank" %>
在App2中有“downloads”和控制器,“download_video”是“downloads”控制器的一个动作:
def download_video
send_file '/path/to/video/video.mp4', type: "video/mp4", :disposition => "inline"
end
单击链接后,将打开一个新窗口(选项卡)并在窗口中播放视频 - 这是一种理想的行为....我的问题是,当查看日志时,我看到相同的GET请求被发送3次 - 第一次作为HTML,然后作为 / 两次:
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:45 +0200
Processing by DownloadsController#download_video as HTML
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-19 16:26:46 +0200
Processing by DownloadsController#download_video as */*
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 0ms
有谁能让我知道为什么会这样,我怎么能阻止它?
谢谢, 乔恩。
@ praga2050,
是的:请你发布整个控制器代码......
class DownloadsController < ApplicationController
def download_video
send_file '/var/www/videos/video.mp4', type: "video/mp4", :disposition => "inline"
end
end
@ praga2050,
是的:...尝试使用时间戳添加Rails.logger.debug并查看
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as HTML
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.2ms)
Completed 200 OK in 1ms
Started GET "/downloads/download_video" for ::1 at 2018-04-20 13:59:42 +0200
Processing by DownloadsController#download_video as */*
Log Date:2018-04-20T13:59:42+02:00
Sent file /path/to/video/video.mp4 (0.1ms)
Completed 200 OK in 1ms