[英]Delete an image with Paperclip
我正在使用Paperclip在我的Rails应用程序中保存图片:
用户模型:
class User < ActiveRecord::Base
has_one :profile
end
档案型号:
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
但它不起作用。 可能吗?
profile = current_user.profile
profile.avatar.destroy
profile.save
你无法以这种方式保存对象current_user.profile.save
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.