Reputation: 4740
I am using WickedPdf
respond_to do |format|
format.html
format.pdf do
render :pdf => "file_name"
end
end
This is working fine . the user is able to download the generated pdf . but i need to store the generated pdf in server for other purposes like mailing etc etc How can i save this generated pdf ?
i tried the following but no idea how to pass the html to wickedpdf wicked_pdf doesn't work -- Ruby on Rails
thanks in advance
Upvotes: 4
Views: 7208
Reputation: 4332
As far as I'm aware you cannot save files from the respond_to block directly, you'll need some sort of script that actually visits that page with the .pdf extension, and saves it.
I recommend wkhtmltopdf as I use it quite often and it renders PDF's very well. This will allow you to save the PDF to the file system.
Upvotes: 1
Reputation: 896
You probably figured this out already, but I'm learning WickedPdf right now and just learned how to save directly in your controller in the respond_to block. There is great documentation on the Git page for this https://github.com/mileszs/wicked_pdf. Here's what I have in my controller for the show action:
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.pdf do
render :pdf => "#{@user.name}",
:save_to_file => Rails.root.join('pdfs', "#{@user.name}.pdf")
end
end
end
This ends up saving it to a folder in my root called "pdfs" as the username.pdf. Hope that helps.
Upvotes: 9