Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Gemfile</strong></p> <pre><code>gem 'prawn' </code></pre> <p><strong>/config/initializers/mime_types.rb</strong></p> <pre><code>Mime::Type.register "application/pdf", :pdf </code></pre> <p><strong>AuditsController</strong></p> <pre><code>def show @audit = Audit.find(params[:id]) respond_to do |format| format.html format.pdf do pdf = Prawn::Document.new pdf.text "This is an audit." # Use whatever prawn methods you need on the pdf object to generate the PDF file right here. send_data pdf.render, type: "application/pdf", disposition: "inline" # send_data renders the pdf on the client side rather than saving it on the server filesystem. # Inline disposition renders it in the browser rather than making it a file download. end end end </code></pre> <p>I used to use the <code>prawnto</code> gem before Rails 3.1, but it doesn't work without a bit of hacking anymore. This is a much cleaner way to instantiate and display the PDF object in 3.1 by accessing Prawn directly.</p> <p>I got this technique straight from one of Ryan Bates' <a href="http://www.railscasts.com" rel="noreferrer">Railscasts</a>. Been using it ever since. You can view that specific episode <a href="http://railscasts.com/episodes/153-pdfs-with-prawn-revised" rel="noreferrer">here</a>. He goes into much more detail about subclassing Prawn and moving the PDF generating code out of the controller. Also shows a lot of useful Prawn methods to get you started. Highly recommended.</p> <p>A lot of the episodes are free, but that revised Prawn episode is one of those that are only available with a paid subscription. At $9/month though, a subscription quickly pays for itself.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload