Attachment_fu and server generated assets (PDF)

Hello,

I using attachment_fu in our application for several data. attachment_fu
works fine for uploaded files.
Now I generating some files (PDF) in an action. These PDF should stored
in the filesystem as an asset directly. So the user can download her/his
PDF documents (1…n) every time again without rendering a new PDF. Has
anybody an idea?
The PDF generated in this way:

pdf=FPDF.new
pdf.AddPage

pdf.XXX

Thanks for helping me,

Daniel

Hello,

I solving the problem myself. I will describe my first solution.
Generation the PDF document with FPDF like this.

pdf=FPDF.new
pdf.AddPage

pdf.XXX

The way of saving the generated PDF to the Filesystem is

pdf.Output(filename)

The challenge was creating a empty attachment_fu asset and saving the
file to this asset.

asset = Asset.new()
asset.filename = filename
asset.content_type = ‘application/pdf’
asset.save

Then there is an empty asset, but nothing correspond with the
asset.public_filename. Solving this by creating the directory structure

FileUtils.mkdir_p(“public”+asset.public_filename.slice(0,asset.public_filename.rindex("/")+1))

and then writing the file

pdf.Output(“public”+asset.public_filename).

Note, a require ‘fileutils’ is needed for using mkdir_p.

If anybody knows a more ruby-way solution, please contact me.