I was confused with two options: generating a PDF view template and saving to PDF. I've successfully implemented the latter with the below changes to my view:

  def showpdf
    if File.exist?("#{@reviewform.title}.pdf")
      h4 "PDF-document already exists."
    else
      pdf = Prawn::Document.new
      pdf.text "#{@reviewform.title}"
      pdf.render_file "#{@reviewform.title}.pdf"
      h4 "PDF-document was successfully saved."
    end
  end

This is just basic stuff to test it.

Can someone still confirm this is the right way, and how would I go about the view template method so when the user visits this view, the pdf format would be rendered and then they could save that?

regards,
seba


Dne 01. 12. 2014 ob 20:20 je Sebastjan Hribar zapisal(a):
Hi guys,

can someone help me with this challenge. I'd like to be able to save reviewforms from my app to PDF files. I'm struggling because there is no explicit examples, but I try to derive the correct way from rails examples.

So, I've made this:

I've created a separate controller for showing a reviewform in a PDF format:

  class ShowPdfN
    def get(form_id)
      if @state.username
        @reviewform = Reviewform.find(form_id)
        render :showpdf
      else
        redirect Login
      end
    end
  end
--------------------------------------------------------
And the view with basic stuff:

  def showpdf
    pdf = Prawn::Document.new
    pdf.text "#{@reviewform.title}"
  end

When I wisit http://localhost:3301/show/pdf/1 there is nothing to display.

Any ideas?

regards,
seba

_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to