technoweenie / attachment_fu

Treat an ActiveRecord model as a file attachment, storing its patch, size, content type, etc.
http://weblog.techno-weenie.net
MIT License
1.02k stars 328 forks source link

attachment_fu + ruby 1.9.1 #25

Open ghost opened 14 years ago

ghost commented 14 years ago

Something goes wrong when I upload:

/!\ FAILSAFE /!\ 2010-09-03 15:21:19 +0200 Status: 500 Internal Server Error can't convert nil into Integer /files/sources/rails/customer-service/vendor/plugins/attachment_fu/init.rb:7:in sprintf' /files/sources/rails/customer-service/vendor/plugins/attachment_fu/init.rb:7:inmake_tmpname' /usr/lib64/ruby/1.9.1/tmpdir.rb:132:in create' /usr/lib64/ruby/1.9.1/tempfile.rb:134:ininitialize' /usr/lib64/ruby/gems/1.9.1/gems/rack-1.1.0/lib/rack/utils.rb:486:in new' /usr/lib64/ruby/gems/1.9.1/gems/rack-1.1.0/lib/rack/utils.rb:486:inblock in parse_multipart' [...]

On ruby 1.8 is ok.

technoweenie commented 14 years ago

Judging by the error message, something is nil that shouldn't be. Looks like the behavior of Tempfiles changed. Send me a pull request if you find a fix that works on ruby 1.8 and 1.9. Thanks!

ghost commented 14 years ago

In attachment_fu/init.rb, in method make_tmpname second argument n is nil in ruby 1.9 when I upload file but don't know why:

def make_tmpname(basename, n) ext = nil sprintf("%s%d-%d%s", basename.to_s.gsub(/.\w+$/) { |s| ext = s; '' }, $$, n, ext) end

papayaah commented 14 years ago

was wondering if anyone has a solution to the problem? this happens on Ruby 1.9/Rails 3.0

ivanpoznyak commented 14 years ago

adding n ||= 0 before calling sprintf (in attachment_fu/init.rb) seems to solve the problem. I can't say if this is a "valid" fix in terms of whether it breaks something, or whether it is working in ruby 1.8.7.

anassirk commented 13 years ago

thanx, @ivanpoznyak. works for me.

ippa commented 13 years ago

I've tried both fixes I've found for this issue: n ||= 0

and sprintf("%s%d-%s%s", basename.to_s.gsub(/.\w+$/) { |s| ext = s; '' }, $$, n, ext) instead of sprintf("%s%d-%d%s", basename.to_s.gsub(/.\w+$/) { |s| ext = s; '' }, $$, n, ext)

in both cases the crashing stops but something happens with my thumbnails.. they all get the same size as the original picture. Not sure if this is repeatable by others or if has something to do with my particular setup. Investigating further ...

daronco commented 13 years ago

Another simple solution that seems to work well:

sprintf('%s%d-%d%s', File::basename(basename, ext), $$, n.to_i, ext)

Notice the:

n.to_i

At: http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions

johnnypez commented 13 years ago

Did anyone get thumbnails to work after implementing the fix for this issue? I think attachment_fu is attachment_fubar on ruby 1.9 :(

enortham commented 12 years ago

Johnypez, I upgraded my app to Ruby 1.9.2 and had to make the fix mentioned above. I was then able to upload images but they weren't being resized nor where the thumbnails being created. I realized that the processor wasn't able to load ImageMagick. After uninstalling and reinstalling rmagick I then had a seg fault and had to also reinstall ImageMagick based on http://stackoverflow.com/questions/2838307/why-is-this-rmagick-call-generating-a-segmentation-fault. Once ImageMagick was up and running fine attachment fu properly resized the images and created thumbnails under 1.9.2.