Ich benutze pdfkit, um pdf zu generieren, mit Rails 5. Wenn ich versuche, Seiten der externen Website zu downloaden, wie Google es funktioniert. Aber wenn ich eine Seite meiner Website herunterladen will, tut es nichts. Der Ladecursor wird für immer geladen.Pdfkit funktioniert nicht lokal
Hier ist mein Code:
Controller/Produkte
def download
@product = Product.find(params[:product_id])
file_content = html_to_pdf(request.url, @product.id)
open_file = File.read(file_content)
send_data(open_file,
filename: "ptf_#{@product.id}",
disposition: 'attachment')
end
Produkte/show
<%= button_to 'download', download_product_path(product_id: @product.id), method: :get} %>
Methode in einem Besorgnis
def html_to_pdf(url, id)
kit = PDFKit.new(url)
file = kit.to_file('ptf_'+ id.to_s + '.pdf')
end
Wenn ich es mit file_content = html_to_pdf('http://google.com', @product.id)
versuche, funktioniert es gut. Das Problem ist lokal. Danke für Ihre Hilfe.
Innerhalb 'Download', was ist der Wert von' request.url'? – Stefan
Der Wert ist "http: // localhost: 3000/fr/products/download/2" – Orsay
Und diese Anfrage wird wieder von 'ProductsController # download' behandelt, oder? Sie rufen die Aktion 'download' rekursiv auf. Wahrscheinlich möchten Sie eine PDF-Datei von "http: // localhost: 3000/fr/products/2" 'erzeugen. – Stefan