Paperclip + Permanent records #804

Closed
link-er opened this Issue Mar 31, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@link-er

link-er commented Mar 31, 2012

Hello
I want to use paperclip gem with permanent_records gem (https://github.com/JackDanger/permanent_records) but I have some problems. When I destroy attachment, not only deleted_at column is set to DateTime.now, but the file itself is deleted too - data_file_type, data_file_size and data_file_name is set to NULL.
Can I do something to avoid this?

@sikachu

This comment has been minimized.

Show comment
Hide comment
@sikachu

sikachu Apr 4, 2012

Contributor

What you could do is override prepare_for_destroy in your model to return true, or add some checking to see that it should destroy the attachment or not.

(Don't return false, as it will halt the chain)

You can see that Paperclip add the callback in https://github.com/thoughtbot/paperclip/blob/v3.0.1/lib/paperclip.rb#L182 which executes https://github.com/thoughtbot/paperclip/blob/v3.0.1/lib/paperclip/instance_methods.rb#L28-33.

Contributor

sikachu commented Apr 4, 2012

What you could do is override prepare_for_destroy in your model to return true, or add some checking to see that it should destroy the attachment or not.

(Don't return false, as it will halt the chain)

You can see that Paperclip add the callback in https://github.com/thoughtbot/paperclip/blob/v3.0.1/lib/paperclip.rb#L182 which executes https://github.com/thoughtbot/paperclip/blob/v3.0.1/lib/paperclip/instance_methods.rb#L28-33.

@sikachu sikachu closed this Apr 4, 2012

@link-er

This comment has been minimized.

Show comment
Hide comment
@link-er

link-er Apr 4, 2012

Thanks for answer, it helped!

link-er commented Apr 4, 2012

Thanks for answer, it helped!

@link-er

This comment has been minimized.

Show comment
Hide comment
@link-er

link-er Jun 8, 2012

    def prepare_for_destroy
        true
    end

  def destroy(force = nil)
    if :force == force
      each_attachment do |name, attachment|
        attachment.send(:queue_existing_for_delete)
      end
    end
    super
  end

I did it in this way, because I do need files to be reoved when destroy is called with :force parametr. But I get an error

undefined method `queue_existing_for_delete' for #<Paperclip::Attachment:0xfc8cb34>

Can you help me please?

link-er commented Jun 8, 2012

    def prepare_for_destroy
        true
    end

  def destroy(force = nil)
    if :force == force
      each_attachment do |name, attachment|
        attachment.send(:queue_existing_for_delete)
      end
    end
    super
  end

I did it in this way, because I do need files to be reoved when destroy is called with :force parametr. But I get an error

undefined method `queue_existing_for_delete' for #<Paperclip::Attachment:0xfc8cb34>

Can you help me please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment