# Attachment\_Fu and Rails 2,1

**URL:** <https://www.ruby-forum.com/t/attachment-fu-and-rails-2-1/140115>\
**Category:** Rails\
**Created:** [June 11, 2008, 1:23am UTC](https://www.ruby-forum.com/t/attachment-fu-and-rails-2-1/140115 "2008-06-11T01:23:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![photomatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@photomatt](https://www.ruby-forum.com/u/photomatt)\
**Post date:** [June 11, 2008, 1:23am UTC](https://www.ruby-forum.com/t/attachment-fu-and-rails-2-1/140115/1 "2008-06-11T01:23:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![photomatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@photomatt](https://www.ruby-forum.com/u/photomatt)\
**Post date:** [June 11, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-rails-2-1/140115/2 "2008-06-11T17:40:56Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![photomatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@photomatt](https://www.ruby-forum.com/u/photomatt)\
**Post date:** [January 26, 2009, 5:40am UTC](https://www.ruby-forum.com/t/attachment-fu-and-rails-2-1/140115/3 "2009-01-26T05:40:41Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![photomatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@photomatt](https://www.ruby-forum.com/u/photomatt)\
**Post date:** [June 12, 2008, 4:07am UTC](https://www.ruby-forum.com/t/attachment-fu-and-rails-2-1/140115/4 "2008-06-12T04:07:15Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
