Wicked_PDF Download Only - Rails 3.1

I am currently running Rails 3.1 and am using the latest version of Wicked_pdf to generate the PDF. I set everything up correctly and the PDF files generated are just fine.

However, I want the user to be able to click a button to DOWNLOAD the PDF. Currently, when clicked, the browser displays the PDF file and displays it on the page.

<%= link_to "Download PDF", { :action => "show", :format => :pdf }, class: 'button nice red large radius', target: '_blank'%> 

My controller.

 def show @curric = Curric.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @curric } format.pdf do render :pdf => @curric.name + " CV", :margin => {:top => 20, :bottom => 20 } end end end 

I pointed to the send_file file, but I have no idea how to use it in this scenario.

Any help is appreciated.

+4
source share
4 answers

Try:

 pdf = render_to_string :pdf => @curric.name + " CV", :margin => {:top => 20, :bottom => 20 } send_file pdf 
+3
source

Expand the configuration that you want to set as an attachment, for example:

 respond_to do |format| format.pdf do render pdf: @curric.name + " CV", disposition: 'attachment' end end 
+10
source

I do like this:

  def show @candidate = Candidate.find params[:id] respond_to do |format| format.html format.pdf do @pdf = render_to_string :pdf => @candidate.cv_filename, :encoding => "UTF-8" send_data(@pdf, :filename => @candidate.cv_filename, :type=>"application/pdf") end end end 

and it works for me; -)

+4
source
 //Download pdf generated from html template using wicket_pdf gem pdf = render_to_string :template => "simple/show" // here show is a show.pdf.erb inside view send_data pdf 
0
source

All Articles