In my application, I use mini_magick and I need to convert images to black and white and sepia tones. In Rails 1,2,3, this used to work: after_resize do |record,img| logger.debug "img = #{img}" logger.debug "record = #{record}" logger.debug "self = #{self}" logger.debug "record.thumbnail = #{record.thumbnail}" if record.thumbnail.to_s.match(/.*_bw/) img.combine_options do |i| i.colors("256") i.colorspace(:GRAY) i.colorspace(:RGB) i.quality 100 end end if record.thumbnail.to_s.match(/.*sepia/) img.combine_options do |i| i.colors("256") i.colorspace(:GRAY) i.colorspace(:RGB) i.fill "#cc9933" i.colorize "30/30/30" i.quality 100 end end end Now that I''m trying to use Rails 2.1, the log file says: img record = #<MiniMagick::Image:0x20e43ac> self = Photo SQL (0.000471) ROLLBACK ApplicationProcessor::on_error: MiniMagick::MiniMagickError rescued: ImageMagick command (mogrify -thumbnail "/var/folders/w2/w2+1jcd4Ge0d24HOVnPL2++++TI/-Tmp-/minimagick5822-1") failed: Error Given 256 /Library/Ruby/Gems/1.8/gems/mini_magick-1.2.3/lib/mini_magick.rb:124:in `run_command'' /Library/Ruby/Gems/1.8/gems/mini_magick-1.2.3/lib/mini_magick.rb:93:in `method_missing'' /Users/matt/Sites/checkout/app/models/photo.rb:28 /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:177:in `call'' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:177:in `evaluate_method'' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:161:in `call'' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:93:in `run'' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in `each'' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in `send'' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in `run'' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:451:in `run_callbacks'' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:440:in `callback_with_args'' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:34:in `process_attachment'' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:21:in . . . So, it seems that the callback is only getting one argument. And it''s getting the mini_magick::Image in the place where it is supposed to get the record. I''ve spent quite a bit of time looking at attachment_fu.rb around line 437 (callback_with_args) to try to figure out how this works, and I''m wondering if anybody else is having any success with attachment_fu and rails 2.1? Are you getting both parameters passed to your callback? Thanks, Matt -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
nitsujweidmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-11 15:40 UTC
Re: Attachment_Fu and Rails 2,1
I just had this same problem with my app, in your before_thumbnail_saved method you no longer pass recrd and thumbnail, only thumbnail. Heres how mine looks now. before_thumbnail_saved do |thumbnail| record = thumbnail.parent thumbnail.user_id = record.user_id thumbnail.parent_id = record.id regards On Jun 10, 5:23 pm, photo matt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> In my application, I use mini_magick and I need to convert images to > black and white and sepia tones. In Rails 1,2,3, this used to work: > > after_resize do |record,img| > logger.debug "img = #{img}" > logger.debug "record = #{record}" > logger.debug "self = #{self}" > logger.debug "record.thumbnail = #{record.thumbnail}" > if record.thumbnail.to_s.match(/.*_bw/) > img.combine_options do |i| > i.colors("256") > i.colorspace(:GRAY) > i.colorspace(:RGB) > i.quality 100 > end > end > > if record.thumbnail.to_s.match(/.*sepia/) > img.combine_options do |i| > i.colors("256") > i.colorspace(:GRAY) > i.colorspace(:RGB) > i.fill "#cc9933" > i.colorize "30/30/30" > i.quality 100 > end > end > > end > > Now that I''m trying to use Rails 2.1, the log file says: > > img > record = #<MiniMagick::Image:0x20e43ac> > self = Photo > > SQL (0.000471) ROLLBACK > ApplicationProcessor::on_error: MiniMagick::MiniMagickError rescued: > ImageMagick command (mogrify -thumbnail > "/var/folders/w2/w2+1jcd4Ge0d24HOVnPL2++++TI/-Tmp-/minimagick5822-1") > failed: Error Given 256 > /Library/Ruby/Gems/1.8/gems/mini_magick-1.2.3/lib/mini_magick.rb:124:in > `run_command'' > /Library/Ruby/Gems/1.8/gems/mini_magick-1.2.3/lib/mini_magick.rb:93:in > `method_missing'' > /Users/matt/Sites/checkout/app/models/photo.rb:28 > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:177:in > `call'' > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:177:in > `evaluate_method'' > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:161:in > `call'' > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:93:in > `run'' > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in > `each'' > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in > `send'' > /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in > `run'' > /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:451:in > `run_callbacks'' > /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:440:in > `callback_with_args'' > /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:34:in > `process_attachment'' > /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:21:in > . > . > . > > So, it seems that the callback is only getting one argument. And it''s > getting the mini_magick::Image in the place where it is supposed to get > the record. > > I''ve spent quite a bit of time looking at attachment_fu.rb around line > 437 (callback_with_args) to try to figure out how this works, and I''m > wondering if anybody else is having any success with attachment_fu and > rails 2.1? Are you getting both parameters passed to your callback? > > Thanks, > > Matt > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
before_thumbnail_saved now does only take one parameter. But, the docs for after_resize still show that it is supposed to be able to take two parameters. Does the following very basic after_resize callback print good results for anybody? Below is one that will just output some information to the log file. after_resize do |record,img| logger.debug "img = #{img}" logger.debug "record = #{record}" logger.debug "self = #{self}" logger.debug "record.thumbnail = #{record.thumbnail}" end unknown wrote:> I just had this same problem with my app, in your > before_thumbnail_saved method you no longer pass recrd and thumbnail, > only thumbnail. Heres how mine looks now. > > before_thumbnail_saved do |thumbnail| > record = thumbnail.parent > thumbnail.user_id = record.user_id > thumbnail.parent_id = record.id > > > regards > > On Jun 10, 5:23�pm, photo matt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think attachment_fu may have some problem working with Rails 2.0 and above. I use a piece of code from the book Practical Rails Social Networking Sites by Alan Bradbune in one of my projects which uses the plugin. It works perfectly with Rails 1.2.6 (and any other version a.2.*) but fails to work with Rails 2.0.2 and 2.1.2. It just complains "NoMethodError (undefined method `callbacks_for'' for #<Photo:0xb4a9a484>)" photo matt wrote:> before_thumbnail_saved now does only take one parameter. > > But, the docs for after_resize still show that it is supposed to be able > to take two parameters. Does the following very basic after_resize > callback print good results for anybody? Below is one that will just > output some information to the log file. > > after_resize do |record,img| > logger.debug "img = #{img}" > logger.debug "record = #{record}" > logger.debug "self = #{self}" > logger.debug "record.thumbnail = #{record.thumbnail}" > end > > > unknown wrote: >> I just had this same problem with my app, in your >> before_thumbnail_saved method you no longer pass recrd and thumbnail, >> only thumbnail. Heres how mine looks now. >> >> before_thumbnail_saved do |thumbnail| >> record = thumbnail.parent >> thumbnail.user_id = record.user_id >> thumbnail.parent_id = record.id >> >> >> regards >> >> On Jun 10, 5:23�pm, photo matt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---