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:
Thanks for helping me,
I solving the problem myself. I will describe my first solution.
Generation the PDF document with FPDF like this.
The way of saving the generated PDF to the Filesystem is
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’
Then there is an empty asset, but nothing correspond with the
asset.public_filename. Solving this by creating the directory structure
and then writing the file
Note, a require ‘fileutils’ is needed for using mkdir_p.
If anybody knows a more ruby-way solution, please contact me.