rails paperclip .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
我遇到这个问题,我想从 s3 中删除文件并让系统 returns 成为默认值 url。但是,在尝试下面的代码并成功删除 s3 中的文件后,url 我仍然指向 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
销毁图像后,需要保存对象:
user = User.first
user.profile_image.destroy
# saving changes to instance
user.save
归功于 this SO answer。
我遇到这个问题,我想从 s3 中删除文件并让系统 returns 成为默认值 url。但是,在尝试下面的代码并成功删除 s3 中的文件后,url 我仍然指向 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
销毁图像后,需要保存对象:
user = User.first
user.profile_image.destroy
# saving changes to instance
user.save
归功于 this SO answer。