rails 回形针 .destroy &.clear 从 s3 中删除文件,但 .url 仍然指向 s3 而不是 default_url [英] rails paperclip .destroy & .clear removes the file from s3, but .url is still directing to s3 instead of default_url

查看:37
本文介绍了rails 回形针 .destroy &.clear 从 s3 中删除文件,但 .url 仍然指向 s3 而不是 default_url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个问题,我想从 s3 中删除文件并让系统返回默认 url.但是,在尝试下面的代码并成功删除 s3 中的文件后,我得到的 url 仍然指向 s3.

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.

我做了以下代码

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

推荐答案

销毁图像后,需要保存对象:

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

user = User.first
user.profile_image.destroy

# saving changes to instance
user.save

归功于这个 SO 答案.

这篇关于rails 回形针 .destroy &.clear 从 s3 中删除文件,但 .url 仍然指向 s3 而不是 default_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆