Using carrierwave with paper_trail

267 views
Skip to first unread message

cristi.prodan

unread,
Mar 22, 2011, 4:17:19 AM3/22/11
to carrierwave
Hi,

I'm trying to include undo support using the paper_trail gem and the
tutorial described in this railscast http://railscasts.com/episodes/255-undo-with-paper-trail.

My model uses carrierwave for pictures manipulation. After deleting an
instance of the model, the file also gets deleted. Is there any way to
prevent that (which would allow restoring the instance of the model
using paper_trail) ?

E.g.

@model.destroy # also deletes the file; I would like to call
something that keeps the file

@model.delete # does not work because the version of the model is not
saved by paper_trail.

Thanks,
Cristi

Jonas Nicklas

unread,
Mar 22, 2011, 4:36:18 AM3/22/11
to carri...@googlegroups.com, cristi.prodan
The ORM adapters call #remove_*column_name*! to remove the file.
Override that method to do nothing, or write your own ORM adapter that
doesn't do that (they're not a lot of code, see:
https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/orm/activerecord.rb).

/Jonas

> --
> You received this message because you are subscribed to the Google Groups "carrierwave" group.
> To post to this group, send email to carri...@googlegroups.com.
> To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.
>
>

frizbe1605

unread,
Mar 30, 2011, 7:18:09 AM3/30/11
to carrierwave
If you are using Mongoid you can include Mongoid::Paranoia which will
just set a deleted_at attribute. The record would no longer be
returned unless explicitly called for ala
@model.where(:deleted_at.exists => true)

On Mar 22, 3:17 am, "cristi.prodan" <prodan.crist...@gmail.com> wrote:
> Hi,
>
> I'm trying to include undo support using the paper_trail gem and the
> tutorial described in this railscasthttp://railscasts.com/episodes/255-undo-with-paper-trail.
Reply all
Reply to author
Forward
0 new messages