I currently run Rails 3.1 and am using the latest version of Wicked_pdf for PDF generation. I have set everything up correctly, and PDFs are generated just fine.
However, I want the user to be able to click a button to DOWNLOAD the pdf. At the present time, when clicked, the browser renders the pdf 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 have been pointed towards send_file, but have absolutely no idea how to use it in this scenario.
Any help is appreciated.
Decomposition the config you need to set as 'attachment', example:
respond_to do |format|
  format.pdf do
    render pdf: @curric.name + " CV",
           disposition: 'attachment'
  end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With