In my previous post about attachment_fu (with rmagick) on windows, I did something sort of silly in the #create action of my controller: Windows required a little time to catch up because the file system loaded the file slower that attachemnt_fu needed it. To solve that problem, I added "sleep 5" immediately before MyObject#save.
The problem with that hack is every time I need to #save I have to remember to insert the "sleep 5" hack. That's a mistake waiting to happen. So, I moved the sleep to the model, like so:
class MyObject < ActiveRecord::Base
def before_save
sleep 5 ## <<-- pauses so Windows can catch up.
end
end
It's much more logical that this code is part of the model because the delay is fundamentally a part saving the object, not a part of responding to an action.
This also address the notion of keeping your controllers skinny and your models fat. Jamis Buck blogs very eloquently about this notion here.
more on attachment_fu on windows
Share This Post On: del.icio.us |
Digg |
Reddit |
Slashdot
Subscribe to:
Post Comments (Atom)
1 comment:
Hi,
Just to let you know that you don't need a timing loop to fix this issue... doing a fsync is just what is needed to fix the issue. (see my post on the subject : http://epirsch.blogspot.com/2008/01/fixing-attachmentfu-on-windows-like.html)
Post a Comment