Send_data 未发送 pdf (WickedPdf)
Send_data not sending pdf (WickedPdf)
我正在尝试生成 pdf 供用户下载。我正在使用 WickedPdf gem.
<%= 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
app/views/admin/reports/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" = LIMIT [["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发送给客户端。任何帮助将不胜感激。
我通过删除 remote: true
让这个工作正常
我正在尝试生成 pdf 供用户下载。我正在使用 WickedPdf gem.
<%= 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
app/views/admin/reports/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" = LIMIT [["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发送给客户端。任何帮助将不胜感激。
我通过删除 remote: true