2014-12-02 3 views
0

링크를 클릭 할 때 pdf 파일을 다운로드하고 싶지만 링크를 클릭하면 pdf 파일이 생성됩니다.Ruby on Rails 동적 파일 다운로드

나는 나의 _assignment_sidebar.html.erb 파일이 있습니다

<ul class="page-action-list"> 
    <li> 
    <a href="#" class="button-sidebar-wide <%= late %>"> 
     <i class='icon-add'></i> <%= t 'links.submit', "Download Coversheet" %> 
    </a> 
    <%= link_to new 
    </li> 
</ul> 

하지만 컨트롤러에 내 기능에 연결하는 방법을 모르겠어요. assignments_controller.rb에서

나는이있다 : PDF를 생성하고 다시보기로 다시 보내야

def pdf 
    #generate pdf and put into 'private' folder 
    send_file Rails.root.join('private', 'output.pdf'), :type=>"application/pdf", :x_sendfile=>true 
end 

.

도움을 주시면 감사하겠습니다.

나는 그것의 단지 같은

require "prawn" 

Prawn::Document.generate("hello.pdf") do 
    text "Hello World!" 
end 

난 그냥 그것의 정말 좋은 문서를 가지고 있지만 나는 새우처럼 사용하지 않은 wicked_pdf gem을 발견 다른 검색을 수행해야한다 본질적으로는 정말 간단 prawn gem에서 살펴 것

답변

0

+0

감사하지만 PDF를 생성하는 방법을 알고 있습니다. html.erb 파일에서 다운로드하는 데 도움이 필요합니다. – sooty1892

+0

http://stackoverflow.com/questions/8537960/download-pdf-instead-of-showing-it-in-the-browser를 확인하십시오. –