paperclip callbacks or simple processor?

2019-03-23 04:11发布

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?

3条回答
何必那么认真
2楼-- · 2019-03-23 04:49

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.

查看更多
Fickle 薄情
3楼-- · 2019-03-23 05:04

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.

查看更多
劫难
4楼-- · 2019-03-23 05:06

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

查看更多
登录 后发表回答