2016-12-07 59 views
0

我想在我的展示页面上放置下载功能,但是页面上没有标志,当页面打开时不自动下载,只有图像下载不起作用。 表演形式 -如何在ROR的展示页面上放置下载选项

<tr> 
    <th><strong>Download Document</strong></th> 
    <td><%= link_to '',download_screenshot_path(id: issue_request.id),class: 'btn btn-xs fa fa-download' %></td> 

    <th><strong>Download Image</strong></th> 
    <td><%= link_to '',download_screenshot_image_path(id: issue_request.id),class: 'btn btn-xs fa fa-picture-o' %></td> 
</tr> 

控制方法 -

def show 
    @issue_request = IssueRequest.find(params[:id]) 
    send_file @issue_request.document1.path, 
      filename: @issue_request.document1_file_name, 
      type: @issue_request.document1_content_type, 
      disposition: 'attachment' 

    @issue_request = IssueRequest.find(params[:id]) 
    send_file @issue_request.document2.path, 
      filename: @issue_request.document2_file_name, 
      type: @issue_request.document2_content_type, 
      disposition: 'attachment' 
end 
+0

**但标志不在页面上** - 您期望在页面上显示什么标志?你没有提供任何东西给'link_to'来命名你的下载链接。 – dp7

+0

我的意思是下载按钮没有进入页面。 –

+0

为您的链接命名:'<%= link_to'下载',download_screenshot_path(id:issue_request.id),class:'btn btn -xs fa fa-download'%>' – dp7

回答

0

不包括在表演方法send_file,会立即做下载。你想要一个单独的行动。

我假设你已经设置了您的下载路径,它们应被设置为是类似的路线......

get '/screenshot', to: 'issue_requests#download_screenshot', as: 'download_screenshot' 

然后在issue_requests_controller.rb你会

def download_screenshot 
    issue_request = IssueRequest.find(params[:id]) 
    send_file issue_request.document1.path, 
      filename: issue_request.document1_file_name, 
      type: issue_request.document1_content_type, 
      disposition: 'attachment' 
end 

并为download_screenshot_image做一些类似的操作,使其具有不同的控制器操作路径。

这种方式只有在单击link_to时才会发生下载。

0

请注明文本的link_to标记,否则按钮不会出现 这样

<%=的link_to '测试按钮',download_screenshot_path(ID:issue_request.id)类:“BTN BTN-XS发发 - 下载'%>

相关问题