Read my latest article: Announcing RailsDeveloper (posted Wed, 01 Sep 2010 17:01:00 GMT)

Rendering a ERb template stored in the database to a PDF

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

11 comments Latest by coach bags Sat, 28 Aug 2010 10:00:48 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
    Stacypog Tue, 14 Aug 2007 15:44:06 GMT

    http://adbrgwefrgedw.host.com desk3 [url=http://adbsgwefrgedw.host.com]desk4[/url] [link=http://adbagwefrgedw.host.com]desk6[/link]

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

    ok

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

    ok

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

    ok

  5. Avatar
    APPLE laptop adapter Thu, 13 May 2010 07:50:14 GMT

    fter doing so, I noticed that Rails trunk included a completely refactored version of action_controller.rb

  6. Avatar
    jewellery earrings Fri, 28 May 2010 06:20:25 GMT
  7. Avatar
    nike watches Sun, 04 Jul 2010 02:11:11 GMT

    So if you are looking for a Nike sports watch, a Nike Ladies watch, or the amazing Nike Ti range of watches, nike watches This is the web site you need. miao silver jewelry

  8. Avatar
    dstt Mon, 09 Aug 2010 03:11:38 GMT

    http://www.ndscardstore.com/ provide a great deal of dstti,dsttand m3i zero ez-flash ezflash vi at the most competitive prices – online Nintendo DS Lite Store.we hope you enjoy the store.

  9. Avatar
    http://www.bestretroshoes.com Wed, 11 Aug 2010 06:01:58 GMT
    air jordan 9,air jordan 9
    air jordan 10,air jordan 10
    air jordan 11,air jordan 11
    Air Jordan Fusion 4.5,Air Jordan Fusion 4.5
    air jordan Flight 7.5,air jordan Flight 7.5
    air jordan 3.5,air jordan 3.5
    Air Jordan,Air Jordan
    Nike boots,Nike boots
    air jordan 12,air jordan 12
  10. Avatar
    Shure microphones Sat, 14 Aug 2010 09:00:39 GMT

    We are a professional exporter and wholesaler of brand fashion products Soundcraft Mixer EFX12 Soundcraft Mixer EFX8 Soundcraft Mixer EPM-12 Soundcraft Mixer EPM-6 Soundcraft Mixer EPM-8 All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.

  11. Avatar
    coach bags Sat, 28 Aug 2010 10:00:48 GMT

    bags Canada[/b][/url], coach bags Canada

    five fingers[/b][/url], vibram five fingers

    UK[/b][/url], MBT UK

    Shoes[/b][/url], masai shoes

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

Comments