From: Rick DeNatale Date: 2010-07-31T23:55:35+09:00 Subject: Re: Problem with a lambda not executing immediately On Fri, Jul 30, 2010 at 5:40 AM, Fernando Perez wrote: >> Given that the key in the hash is >> :processors (in plural) I would assume that the value should be an >> array of processors. > > Yes style.processors is expected to be an array > >> So, even if you only have one lambda, can you try this: >> >> class Asset < ActiveRecord::Base >>   has_attached_file :data, :styles => { >>     :theora => [:format => :ogv, :processors => [lambda {|a| a.video? >> ? [:video_converter] : []}]}] >> } > > Unfortunately it doesn't work, as when the lambda gets executed, the "a" > object it receives is not the not it expects: "wrong constant name > passed". I suspect that you would get better answers on the rails forum since paperclip is better known there than in the general Ruby community. but.. First, the :processors option isn't supposed to be part of the :style hash has_attached_file :date, :styles => {:theora => {:format => :ogv}, :processors => [ # something goes here ] Now it appears you are trying to use a feature of paperclip which doesn't seem to be documented, normally the value for the :processors option is just an array of symbols which are converted to an instance of a subclass of Paperclip::Processor. But from reading the code it appears that you can also do: class Asset < ActiveRecord::Base has_attached_file :date, :styles => {:theora => {:format => :ogv}, :processors => lambda { | asset | # the instance of the Asset model asset.video? ? [:video_converter] : [] } end I'd probably refactor this a bit: class Asset < ActiveRecord::Base has_attached_file :date, :styles => {:theora => {:format => :ogv}, :processors => lambda { | asset | asset.processors } def processors self.video? ? [:video_converter] : [] end end I've tested none of this so take it with the appropriate grain of salt. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale