开发者

Delete an image with Paperclip

开发者 https://www.devze.com 2023-02-18 00:41 出处:网络
I\'m using Paperclip to save pictures in my Rails application: User model: class User < ActiveRecord::Base

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

0

精彩评论

暂无评论...
验证码 换一张
取 消