Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paperclip callbacks or simple processor?

I wanted to run the callback after_post_process but it doesn't seem to work in Rails 3.0.1 using Paperclip 2.3.8. It gives an error:

undefined method `_post_process_callbacks' for #<Class:0x102d55ea0>

I want to call the Panda API after the file has been uploaded. I would have created my own processor for this, but as Panda handles the processing, and it can upload the files as well, and queue itself for an undetermined duration I thought a callback would do fine. But the callbacks don't seem to work in Rails3.

after_post_process :panda_create

    def panda_create
      video = Panda::Video.create(:source_url => mp3.url.gsub(/[?]\d*/,''), :profiles => "f4475446032025d7216226ad8987f8e9", :path_format => "blah/1234")
    end

I tried require and include for paperclip in my model but it didn't seem to matter.

Anyideas?

like image 549
holden Avatar asked Dec 24 '10 20:12

holden


3 Answers

Solution...

I put the callback after the paperclip has_attached in the given model and it works beautifully. I was just so used to always putting the callback at the top of all models that this didn't occur to me til later.

like image 165
holden Avatar answered Nov 15 '22 06:11

holden


Moving the has_attached_file attribute above the validates_presence_of and validates_attachment in your model still needs to be done it seems. I just ran into the same problem in my Rails 4/Ruby 2 implementation of PaperClip and putting it above fixed it.

like image 29
JCC Avatar answered Nov 15 '22 05:11

JCC


I ran into this problem because the name of my paperclip image property did not match the name I was validating against.

as_attached_file :image validates_attachment_content_type: :not_image

like image 35
Tom Avatar answered Nov 15 '22 05:11

Tom