title: Using Prawn with rails app: Send generated pdf file to user's downloads folder instead of app directory
body: <p>In a controller I have the following line in one of the actions:</p>
  
  <pre><code>def some_action
    @blog = Blog.find(11)
    PdfSingleBlog.new(@blog).print
  end
  </code></pre>
  
  <p>That <code>PDfSingleBlog</code> is just a PORO class acting as a service.  The service's job is obviously to generate a pdf of this blog and it is supposed to send that pdf to the user's downloads folder. That code is located here:</p>
  
  <pre><code>#app/services/pdf_single_blog.rb
  class PdfSingleBlog
  
    def initialize(blog)
      @blog = blog
    end
  
    def print
      pdf = Prawn::Document.new
      pdf.text "Blog Name: #{@blog.name}"
      pdf.text "Description: #{@blog.description}"
      pdf.render_file "blog_info.pdf"
    end
  end
  </code></pre>
  
  <p>The pdf is successfully generated, however it is not sending it to the user's downloads folder.  Instead it is saving it to the directory of the application on the server.</p>
  
  <p>How do I actually send the generated pdf to the user's downloads folder?</p>
  
  <p><a href="http://prawnpdf.org/manual.pdf" rel="nofollow">PDF of prawn manual found here</a>
  <hr>
  <strong>Updated with Answer below:</strong></p>
  
  <hr>
  
  <pre><code>def some_action
    @blog = Blog.find(11)
    blog_pdf = PdfSingleBlog.new(@blog).prepare_for_print
    send_data blog_pdf.render, filename: "blog.pdf", type: "application/pdf"
  end
  
  #app/services/pdf_single_blog.rb
  class PdfSingleBlog
  
    attr_reader :blog
    def initialize(blog)
      @blog = blog
    end
  
    def prepare_for_print
      pdf = Prawn::Document.new
      pdf.text "Blog Name: #{@blog.name}"
      pdf.text "Description: #{@blog.description}"
      return pdf
    end
  end
  </code></pre>