Edward Stembler
2011-Mar-14 17:41 UTC
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Vladimir Rybas
2011-Mar-14 21:59 UTC
Re: Correct pattern for manually adding Paperclip attachment?
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?
On Mon, Mar 14, 2011 at 8:41 PM, Edward Stembler
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> 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.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.