Search code examples
ruby-on-railscarrierwavecloudinaryuploadcare

Rails + Mongoid + Carrierwave + Cloudinary


I'm migrating from Uploadcare to Cloudinary.

But when I try to update the file field, the field is setting with "old"

p = Photo _id: 556d225e69702d45b0000000, created_at: 2015-06-02 03:26:22 UTC, updated_at: 2015-06-02 03:26:22 UTC, file: nil
p.file = p.id
p.save

Returning

Photo _id: 556d225e69702d45b0000000, created_at: 2015-06-02 03:26:22 UTC, updated_at: 2015-07-30 19:41:12 UTC, file: "_old_"


p.file = <PhotoUploader:0x007fe96fc86800 @model=#<Photo _id: 556d225e69702d45b0000000, created_at: 2015-06-02 03:26:22 UTC, updated_at: 2015-07-30 19:41:12 UTC, file: "_old_">, @mounted_as=:file, @stored_public_id=nil, @stored_version=nil, @file=nil, @original_filename=nil, @public_id=nil, @storage=#<Cloudinary::CarrierWave::Storage:0x007fe9701f8f18 @uploader=#<PhotoUploader:0x007fe96fc86800 ...>>>

Any suggestion?


Solution

  • I figured it out the problem!

    Carrierwave don't let you change the upload column If there is no image uploaded before.

    So...you have to upload a sample image before

    p = Photo.find(:id)
    p.remote_file_url = "http:sample.com/image.png"
    p.save
    

    Then... change the your photo_uploader.rb to Cloudinary options

    include Cloudinary::CarrierWave
    

    And finally...

    p.file = 'cloudinary public id'
    p.save
    

    And GOTCHA!