唯一我已经看到了这个话题比较有用的线程是在这里:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/709d97e06b373786
我觉得Matchu的解决方案可能是正确的与attachment_fu代码的快速审查。如果可以分享补丁或修改后的save_attachment片段,我会喜欢它吗?方法。我即将挖成这个我自己,因为这已经成为我的问题,它可能会比完全取代attachment_fu工作量少...
更新
随着Matchu的轮廓,我想出了一个简短的(如果不够优雅的)解决方案,似乎在轻度测试后就可以工作。
我修改了save_attachment?在attachment_fu/attachment_fu.rb中:
def save_attachment?
return false unless (thumbnail || !full_filename || @active_upload) #added
File.file?(temp_path.to_s)
end
...检查条件是否正确。我无法想出一个优雅的方式来判断数据是否已经传递到uploaded_data = setter方法(如果有人有更好的方法来做到这一点,我都耳熟能详;我仍然是一个ruby/rails noob ),所以我还添加了一行到uploaded_data =设置全局变量@active_upload:
def uploaded_data=(file_data)
return nil if file_data.nil? || file_data.size == 0
self.content_type = file_data.content_type
self.filename = file_data.original_filename if respond_to?(:filename)
@active_upload=true # added
if file_data.is_a?(StringIO)
file_data.rewind
self.temp_data = file_data.read
else
self.temp_path = file_data
end
end
希望帮助,如果任何人有一个更优雅的方式来处理我与全局变量确实存在,我d爱听到它。
这对我来说似乎很陌生。你有没有在AttachmentFu开发者邮件列表上发布它?获得一个“权威”的理由可能会有助于将该行为发回SO社区,或者如果它是不理想的行为,则可以提供补丁。 – 2009-05-29 04:35:02