Rendering a ERb template stored in the database to a PDF 3
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. :-)
Enjoying the content? Be sure to subscribe to my RSS feed.





ok
ok
ok