2017-08-16 99 views
0

我正在嘗試爲用戶下載生成pdf。我正在使用WickedPdf寶石。Send_data not sending pdf(WickedPdf)

<%= simple_form_for :report, url: [:download, :admin, :reports], format: :pdf, method: :get, remote: true do |f| %> 
    <%= f.input :event, collection: @events %> 
    <%= f.input :report_type, collection: [:schedule, :overview] %> 
    <%= f.submit "Download" %> 
<% end %> 



class Admin::ReportsController < Admin::BaseController 

    def index 
    @events = Event.all 
    end 

    def download 
    respond_to do |format| 
     format.pdf do 
     pdf = WickedPdf.new.pdf_from_string(pdf_string) 
     send_data pdf, :filename => "report.pdf", :type => "application/pdf" 
     end 
    end 
    end 

    private 

    def pdf_string 
    render_to_string(template:'admin/reports/pdf/schedule_overview.html.erb', layout: false) 
    end 

end 

應用程序/視圖/管理/報告/ PDF/schedule_overview.html.erb

This is a pdf 

(只是文本ATM)

服務器請求時:

Started GET "/admin/reports/download?utf8=%E2%9C%93&report%5Bevent%5D=1&report%5Breport_type%5D=schedule&commit=Download" for ::1 at 2017-08-16 16:18:49 +0100 
Processing by Admin::ReportsController#download as JS 
    Parameters: {"utf8"=>"✓", "report"=>{"event"=>"1", "report_type"=>"schedule"}, "commit"=>"Download"} 
    User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]] 
    Rendering admin/reports/pdf/schedule_overview.html.erb 
    Rendered admin/reports/pdf/schedule_overview.html.erb (0.8ms) 
"***************[\"/Users/jonathansayer/.rvm/gems/ruby-2.4.0/bin/wkhtmltopdf\", \"-q\", \"file:////var/folders/0x/g3xdsy4s48q9y0lpzsppltv80000gn/T/wicked_pdf20170816-33407-4r72d4.html\", \"/var/folders/0x/g3xdsy4s48q9y0lpzsppltv80000gn/T/wicked_pdf_generated_file20170816-33407-1hnp6hr.pdf\"]***************" 
    Rendering text template 
    Rendered text template (0.1ms) 
Sent data report.pdf (1.9ms) 
Completed 200 OK in 1803ms (Views: 1.4ms | ActiveRecord: 0.6ms)) 

但是沒有pdf發送給客戶端。任何幫助將不勝感激。

+0

得到了這個工作我猜格式應該是'pdf'不'js' –

+0

是,更新。但仍然沒有解決這個問題。 – JonSayer

+0

你能顯示你的更新代碼嗎? –

回答