Correct pattern for manually adding Paperclip attachment?

Can anyone point me to the correct pattern for manually adding a
Paperclip attachment?

By manual, I mean that I’m not using an upload form. For example, I’m
programmatically creating the attachment (i.e. an CSV file, or Excel
document). I’ve noticed that 1) Paperclip prefers to use Rail’s custom
Tempfile class, and 2) that Paperclip prefers to move the file. 3) On
Windows, I’ve noticed it doesn’t like it when the file path is the same
place it wants to move it to; it fails, whereas on Mac OS X (or Unix) is
does not fail.

I’ve tried creating the file in Rail’s tmp folder first, and I’ve also
created a fake Uploadfile class which has the original_filename and
content_type accessors. However, I’m not clear on the proper pattern.
Should I just set the attachment property name to the
File/Uploadfile/Tempfile? Should I use assign?

I’ve noticed with my Excel file, that Paperclip corrupts it after moving
it. My guess is that it is saving the file in text mode instead of
binary.

class Document < ActiveRecord::Base
has_attached_file :file
end

Document.new :file => File.open(‘C:\Whatever\the\path\is.xls’)

Would it work for you?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs