Read my latest article: Was away on vacation (posted Sun, 11 May 2008 22:33:00 GMT)

Rendering a ERb template stored in the database to a PDF 3

Posted by Robby Russell Sat, 04 Jun 2005 22:59:00 GMT

In my PDF generation project, I would like the PDF templates to be stored in the database rather than on the file system. (not everyone who admins the system should have access to the file system).

So, what I did, after playing with all the different render_* methods in Action Controller, was create a new method called render_string_to_string. This marks my first attempt to submit a patch. After doing so, I noticed that Rails trunk included a completely refactored version of action_controller.rb. Perhaps this functionality exists in trunk now, I haven’t had a chance to play with it yet.

However, in the meantime, I can do this:

    letter_template = LetterTemplate.find_by_id(1)

    foo = render_string_to_string(letter_template.body)

    pdf=FPDF.new
    pdf.AddPage
    pdf.SetFont('Times')
    pdf.SetFontSize(12)

    pdf.Write(5, foo)

    pdf.Output


This is the first time that I have started to tinker (all 4 lines) with the actual Rails code base. I’ve wandered around it, but have stuck to using Rails rather than trying to modify it.

If there is a better way to handle this, please let me know. :-)

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    nick Fri, 05 Oct 2007 17:56:02 GMT

    ok

  2. Avatar
    nick Fri, 05 Oct 2007 17:56:04 GMT

    ok

  3. Avatar
    nick Fri, 05 Oct 2007 18:56:51 GMT

    ok

Share your thoughts... (really...I want to hear them)

Comments