用回形针删除图像 [英] Delete an image with Paperclip
本文介绍了用回形针删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用户模型:
class User< ActiveRecord :: Base
has_one:个人资料
结束
个人资料模型: p>
class Profile< ActiveRecord :: Base
has_attached_file:avatar,:styles => {:medium => 300x300>,:thumb => 100x100>}
belongs_to:user
end
我尝试删除头像:
current_user.profile.avatar = nil
current_user.profile.save
code>
但是不起作用。是否有可能?
解决方案
profile = current_user.profile
profile.avatar .destroy
profile.save
不能以这种方式保存对象 current_user.profile.save
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?
解决方案
profile = current_user.profile
profile.avatar.destroy
profile.save
You can't save object this way current_user.profile.save
这篇关于用回形针删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文