paperclip callbacks or simple processor?

淺唱寂寞╮ 提交于 2019-12-09 07:53:57

问题


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?


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4528287/paperclip-callbacks-or-simple-processor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!