【发布时间】:2015-07-29 17:51:03
【问题描述】:
我有这个问题,我想从 s3 中删除文件并让系统返回默认 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.profile_image.destroy之后检查user.profile_image会发生什么 -
回形针附件还在,
profile_image_file_name和profile_image_file_size等其他内容仍然存在,而不是零 -
您不认为
user.profile_image.destroy工作不正确吗?因为它没有删除 profile_image。? -
我只是尝试了其他方法。在
user.profile_image.destory我也必须做user.update(profile_image_file_name: nil, profile_image_content_type: nil, profile_image_file_size: nil, profile_image_updated_at: nil)然后当我打电话给user.profile_image.url时,它会给我我指定的适当的default_url -
销毁后需要保存对象(
user.save)。见this answer。
标签: ruby ruby-on-rails-4 paperclip