Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicked_PDF Download Only - Rails 3.1

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.

like image 890
Ammar Avatar asked Dec 01 '22 07:12

Ammar


1 Answers

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
like image 192
aquajach Avatar answered Dec 05 '22 02:12

aquajach