Attachment_fu Tip
I installed the latest version of attachment_fu for a project I’m working on. I ran into a problem that I wanted to document here in case anyone else runs into the same thing.
The before_thumbnail_saved callback in attachment_fu is useful for tasks like giving thumbnail versions the same attributes that parent images have. So if an image belongs to an artist, the callback can give the thumbnail the same artist_id as the parent. The callback originally yielded two values to a block—record and thumbnail—like this:
1 2 3 4 | before_thumbnail_saved do |record, thumbnail| thumbnail.artist_id = record.artist_id thumbnail.visible = record.visible end |
But now it yields only one value: thumbnail. To get the same functionality as before, you will need to add a line of code to first find the parent record.
1 2 3 4 5 | before_thumbnail_saved do |thumbnail| record = thumbnail.parent thumbnail.artist_id = record.artist_id thumbnail.visible = record.visible end |
If you haven’t tried attachment_fu yet, here are some links you may find helpful:
