rails paperclip .destroy & .clear removes the file

2019-08-10 16:09发布

I have this problem where I want to delete the file from s3 and have the system returns me the default url. However upon trying the code below and successfully deleting the files in s3, the url I get still points to s3.

I did the following code

user = User.first
user.profile_image.destroy
# i also tried
# user.profile_image.clear

render json: {profile_image: user.profile_image.url}
# the url that paperclip gives me is still points to the s3 server instead of my default picture link

1条回答
甜甜的少女心
2楼-- · 2019-08-10 16:25

After destroying the image, you need to save the object:

user = User.first
user.profile_image.destroy

# saving changes to instance
user.save

Credit to this SO answer.

查看更多
登录 后发表回答