Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete an image with Paperclip

I'm using Paperclip to save pictures in my Rails application:

User model:

class User < ActiveRecord::Base
  has_one :profile
end

Profile model:

class Profile < ActiveRecord::Base
  has_attached_file :avatar, :styles => {:medium => "300x300>", :thumb => "100x100>"}
  belongs_to :user
end

I try to delete the avatar with:

current_user.profile.avatar = nil
current_user.profile.save

but it doesn't work. Is it possible?

like image 743
Marco Antelmi Avatar asked Mar 17 '11 19:03

Marco Antelmi


1 Answers

profile = current_user.profile
profile.avatar.destroy
profile.save

You can't save object this way current_user.profile.save

like image 73
fl00r Avatar answered Sep 25 '22 17:09

fl00r