What have you found for these years?

2011-06-02

rant (0) attachment_fu on ruby 1.9.2

attachment_fu yet again caused a mysterious break on Ruby 1.9.2.
mini_magick was always complaining that the image was invalid.
I first tried it in plain Ruby, everything is fine.
Then I tried in Rails console, it's broken.
Then I tried in a new Rails console, everything is fine.
Then I tried to remove attachment_fu, everything is fine.
Finally tackled down to attachment_fu/init.rb, this was
the cause:
Tempfile.class_eval do
  # overwrite so tempfiles use the extension of the basename.
  # important for rmagick and image science
  def make_tmpname(basename, n)
    ext = nil
    sprintf("%s%d-%d%s", basename.to_s.gsub(/\.\w+$/) { |s|
      ext = s; '' }, $$.to_i, n.to_i, ext)
  end
end
After removing this monkey patch, everything is fine now.

Gees, this is the thousandth time I need to fix attachment_fu.
I hope people won't do this kind of monkey patch nowadays!

Rails hate, Rails plugins hate...
Did people learn to program in Rails 3 now?

2 retries:

ihower said...

沒用 attachment_fu 很久了,這 plugin 還有人維護嗎 XD
現在王道是 paperclip 和 carrierwave

Lin Jen-Shin (godfat) said...

好久以前我送的 pull request 沒人理,
我就認定他沒人維護了 :o...
(更何況我根本不知道哪個 fork 是主流...)

paperclip 可以用在新 project 上,聽說不錯
carrierwave 倒是沒聽過

要把這一堆 rails 2 的 plugin 搞定,真的很痛苦
希望 rails 4 出來時,不會再有這麼淒慘的事..

謝啦

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0