0

I am trying to delete images in Cloudinary from my Rails application using the following code

def destroy
    media = Media.find(params[:id])

    Cloudinary::Uploader.destroy(media.image_id)
    media.destroy

    respond_to do |format|
        format.html { redirect_to :action => 'index' }
        format.xml { head :ok }
    end
end

Aside from the Uploader.destroy method not actually deleting the image file from my media library^, what I need is to get any return code or error information from the operation. If the delete fails for any reason, I don't want to continue on and delete the media record from the database.

I've been looking through the Cloudinary gem and Googling, but haven't seen anything obvious. Can anyone show me what to do here?

^ I think it's not deleting because I am giving it the wrong image_id. Still working on that.

John Judd
  • 750
  • 7
  • 22
  • [Sample error here](http://cloudinary.com/documentation/upload_images) and details on [Rails API here](http://cloudinary.com/documentation/rails_image_upload). – mccannf Jul 31 '14 at 08:35
  • Where do I get the error response from? Is there a method I need to call, or is it in a variable? – John Judd Jul 31 '14 at 08:48
  • Did you try `result = Cloudinary::Uploader.destroy(media.image_id)` and logging the contents? – mccannf Jul 31 '14 at 16:59

1 Answers1

1

Cloudinary returns the result of the deletion. You can use something like:

result = Cloudinary::Uploader.destroy(media.image_id)

and then check whether result["result"] is "ok" or "not found"

Itay Taragano
  • 1,901
  • 1
  • 11
  • 12