有关carrierwave和mongoid的回调问题

Jon*_*han 6 ruby-on-rails mongoid carrierwave

我在rails 3应用程序上使用了carrierwave和mongoid,并且遇到了after_save回调问题.考虑以下

class Video
  include Mongoid::Document

  field :name  

  mount_uploader :file, VideoUploader

  after_create :enqueue_for_encoding

  protected

  def enqueue_for_encoding
     // point your encoding service to where it expects the permanent file to reside
     // in my case on s3 
  end

end
Run Code Online (Sandbox Code Playgroud)

我的问题是在我的enqueue_for_encoding方法中,file.url指向本地tmp目录而不是s3目录.

enqueue_for_encoding当file.url指向s3时,如何调用我的方法?

谢谢!

乔纳森

the*_*RON 0

您可以尝试删除after_create模型中的回调并将以下内容添加到上传器中:

# video_uploader.rb

process :encode

def encode
  model.enqueue_for_encoding
end
Run Code Online (Sandbox Code Playgroud)

回调在文件保存后被process调用(我认为),这应该允许您在文件在 S3 上启动后挂接。