attachment_fu, deferred thumbnail li

Hi,

I'm using attachment_fu with great success, but have run into a
requirement that I'd like to solve elegantly -- but I've outstripped my
ruby skills.
I have a class that returns a hash of thumbnail definitions, like so:
    class Thumb
       def self.get_thumbs(style)
          return { :small => "100x50", :large => "200x100" } if style
== 'landscape'
          return { :small => "50x100", :large => "100x200" } if style
== 'portrait'
       end
    end

My attachment model is defined like this:

    class Photo < ActiveRecord::Base
         has_attachment :content_type => :image,
             :thumbnails => Thumb.get_thumbs(???)
       […more stuff …]
    end

My photos controller has the following line:

     @photo = Photo.new(params[:photo])

My question:

I'd like dynamically determine what value to set to Thumbnail.get_thumbs
based on values set in the Photo.new constructor. Is this possible?
I've fooled around with attr_accessors, lambdas, etc, but, I can't seem
to do what I want. Is it possible to make such a run-time decision as
I'm trying to make?

Which is to say, if params[:photo][:style] = 'portrait', i'd like to cut
the thumbnails accordingly?

Does anyone have an elegant solution for this?

Elliott Blatt wrote:

Hi,

I'm using attachment_fu with great success, but have run into a
requirement that I'd like to solve elegantly -- but I've outstripped my
ruby skills.
I have a class that returns a hash of thumbnail definitions, like so:
    class Thumb
       def self.get_thumbs(style)
          return { :small => "100x50", :large => "200x100" } if style
== 'landscape'
          return { :small => "50x100", :large => "100x200" } if style
== 'portrait'
       end
    end

My attachment model is defined like this:

    class Photo < ActiveRecord::Base
         has_attachment :content_type => :image,
             :thumbnails => Thumb.get_thumbs(???)
       […more stuff …]
    end

My photos controller has the following line:

     @photo = Photo.new(params[:photo])

My question:

I'd like dynamically determine what value to set to Thumbnail.get_thumbs
based on values set in the Photo.new constructor. Is this possible?
I've fooled around with attr_accessors, lambdas, etc, but, I can't seem
to do what I want. Is it possible to make such a run-time decision as
I'm trying to make?

Which is to say, if params[:photo][:style] = 'portrait', i'd like to cut
the thumbnails accordingly?

Does anyone have an elegant solution for this?

A non-thread-safe solution may be:

after_save 'attachment_options[:thumbnails] = Thumb.get_thumbs(style)'
has_attachment :content_type => :image,
                :thumbnails => Thumb.get_thumbs('landscape')

but a better solution may be to add PortraitPhoto and LandscapePhoto
sub-classes.