Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply processor with paperclip if condition it's true

I have a model with paperclip ruby gem. I defined an attached file with 2 processors (thumbnail and watermark).

The question is if exist the way to apply the watermark processor if condition is true. (the idea it's not define new attached_files without watermark processor)

Thanks in advance.

I try using this code, but dosen't works. If the field eid exist process with watermark else if null process only thumbnail

:processors => lambda { |a|
                if a.eid.nil?
                        [:thumbnail,:watermark]
                else
                        [:thumbnail]
                end
                },
like image 997
jgiunta Avatar asked Dec 21 '11 13:12

jgiunta


1 Answers

The processors option could accept proc, so you could make your processors depend on instance:

:processors => lambda{ |attachment|
   attachment.instance.some_method_to_get_processors_here
},
like image 64
Mark Huk Avatar answered Nov 15 '22 05:11

Mark Huk