2016-12-07 38 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發發 - 下載'%>

相關問題