Carrierwave Cannot Remove Image

Carrierwave cannot remove image

Simply add remove_image to your attr_accessible list

Cannot remove the last image file of a collection in carrierwave

As I mentioned at the issue that I've opened, the CarrierWave deliberately rejects empty or nil values for the uploader columns, so I have come up with a hack to bypass the restriction, and it works well!

@instance.write_attribute(:images, nil)

Image not deleting Carrierwave

CarrierWave requires that you add something like the following to your portfolio_image_attributes:

:_destroy

Once you add that, you'll need to update your checkbox to reference that attribute. I'm not sure if you created ":remove_image" yourself, but I don't think it's necessary.

I added a checkbox (actually, in my app it's a hidden field) that looks like this:

<%= f.hidden_field :_destroy %> #(Where f references my portfolio_image, NOT my portfolio)

Then, upon clicking the X (which references my hidden_field) and submitting my form, the image is removed. Remember, if your image uploader is a has_many relation with the a parent model, you need to add allow_destroy: true to the accepts_nested_attributes. Otherwise it will not allow you to destroy the image from the parent form.

portfolio.rb:

has_many :portfolio_images, dependent: :destroy
accepts_nested_attributes_for :portfolio_images, allow_destroy: true

Ruby On Rails [Carrierwave]: Cannot delete image

In your EventPicture model you have dependent: :destroy on the association which means that when the picture will deleted the corresponding events too. So just edit the association and make it:

belongs_to :event

And you have dependent destroy on the Event model so when a event will be deleted the corresponding pictures too will get deleted which is correct.

Hope this helps.

How to implement Carrierwave's Removing uploaded files?

You just need to add :remove_logo to update_params.

Then you can get rid of the following:

if params[:remove_logo]
@user.remove_logo!
@user.save
end

Carrierwave files not deleting from S3

I would update your store_dir to be:

"uploads/videos/#{mounted_as}/#{model.id}" 

So that carrierwave, while utilizing the mounting system, removes the file, it knows where to find it when it calls the full name method internally!

Cannot upload image by carrierwave

After viewing the source of CarrierWave::Workers::StoreAsset#perform,
the reason why the image cannot be uploaded is because of embedded documents.

The line from source record = resource.find id will return nil because resource is an embedded class and you cannot find id by an embedded class.

To solve the problem, see here. My code should work if I add the following:

class Event
include Mongoid::Document

embeds_many :images
end

class EventImage
include Mongoid::Document

embedded_in :Event

mount_uploader :image, ImageUploader
process_in_background :image

def self.find(id)
bson_id = Moped::BSON::ObjectId.from_string(id) # needed for Mongoid 3

root = Event.where('images._id' => bson_id).first
root.images.find(id)
end
end

If you get the error uninitialized constant Moped::BSON, make sure to require it in the first place.



Related Topics



Leave a reply



Submit