2008/01/10

attachment_fu on Windows

http://railsforum.com/viewtopic.php?id=6307
Code :   fold - unfold
  1.       def uploaded_data=(file_data)
  2.         return nil if file_data.nil? || file_data.size == 0
  3.         self.size = file_data.size
  4.         self.content_type = file_data.content_type
  5.         self.filename     = file_data.original_filename if respond_to?(:filename)
  6.         if file_data.is_a?(StringIO)
  7.           file_data.rewind
  8.           self.temp_data = file_data.read
  9.         else
  10.           self.temp_path = file_data.path
  11.         end
  12.       end
and added conditionals for the size
      

Code :   fold - unfold
  1.       def set_size_from_temp_path
  2.           self.size = File.size(temp_path) if save_attachment? && (self.size == 0 || self.size.nil?)
  3.       end

Posted by Adam (Guest) 
on 10.04.2007 01:34
http://www.ruby-forum.com/topic/99870
To get things working with S3 and windows, I changed:        def temp_data         if save_attachment?           f = File.new( temp_path )           f.binmode           return f.read         else           return nil         end       end (before, the method body was save_attachment? ? File.read( temp_path ) :  nil  ) 

0 comments:

Post a Comment