On Thu, Jul 29, 2010 at 10:38 PM, Fernando Perez <pedrolito / lavache.com> wr=
ote:
> Hi,
>
> I'm using the paperclip plugin for one of my rails app, but my problem
> is pure Ruby. I'm not good enough with Ruby and lambdas so I need your
> advice.
>
> Here is the code I am trying to make work:
>
> class Asset < ActiveRecord::Base
>
> =A0has_attached_file :data, :styles =3D> {
> =A0 =A0:theora =3D> [:format =3D> :ogv, :processors =3D> lambda {|a| a.vi=
deo? ?
> [:video_converter] : []}}]
> }
>
> end
>
>
> What fails is the lambda, because in Paperclip behind the scenes this is
> what happens:
>
> @var =3D style.processors.inject(something) do |file, processor|
> ...
> end
>
> style.processors has received the lambda defined earlier.
>
>
> And I get the following error message:
>
> NoMethodError (undefined method `inject' for #<Proc:0x455d864>)
>
>
> So how can I fix it, and after that which book or resources can I read
> to get proficient in such dynamic coding practice? Currently in use
> blocks all the time ([array].each { ...}) without really mastering them.

I have no idea about paperclip, but looking at the above snippets
style.processor should be an Enumerable (which is where inject is
defined), for example an array. Given that the key in the hash is
:processors (in plural) I would assume that the value should be an
array of processors. So, even if you only have one lambda, can you try
this:

class Asset < ActiveRecord::Base
  has_attached_file :data, :styles =3D> {
    :theora =3D> [:format =3D> :ogv, :processors =3D> [lambda {|a| a.video?
? [:video_converter] : []}]}]
}

Jesus.