CarrierWave support

mrbrdo edited this page Apr 12, 2013 · 10 revisions

There is support for CarrierWave uploads to be moderated (only File store supported). If you need some more customization look at this module in lib/has_moderated/carrier_wave.rb and make your own version. I've only tested it for file storage, if you need some other storage type open an issue and we'll try to figure something out.

Example of moderating uploads

This will moderate the upload no matter if the record is being created, or updated. Other unmoderated fields will be saved normally.

mount_uploader :avatar, GenericUploader
include HasModerated::CarrierWave
has_moderated_carrierwave_field :avatar
has_moderated :avatar

Example of moderating create of the whole model using a CarrierWave uploader

This will moderate creating the whole record (all its fields), including the upload.

mount_uploader :avatar, GenericUploader
include HasModerated::CarrierWave
has_moderated_create
has_moderated_carrierwave_field :avatar

Make sure you call the methods in the correct order as in above example.

To also moderate later changes to the upload (avatar), additionally add

has_moderated :avatar

Example of moderating on association

If you are moderating some other model, and the model with the upload is an association to it, you still need to add this

mount_uploader :avatar, GenericUploader
include HasModerated::CarrierWave
has_moderated_carrierwave_field :avatar

This will only moderate the upload when it's being saved through an association which has

has_moderated_association :photos

Preview (v1.1.5+)

When using preview or live_preview, you will be able to see the upload image from the temporary directory. When accepting the moderation, the image will be moved to the proper location.