【发布时间】:2018-02-02 19:58:35
【问题描述】:
我最近将我的项目升级到最新的 Rails 版本 (5.2) 以获得 ActiveStorage - 一个处理附件上传到 AWS S3、Google Cloud 等云服务的库。
几乎一切正常。我可以上传和附加图片
user.avatar.attach(params[:file])
并收到它
user.avatar.service_url
但现在我想替换/更新用户的头像。我以为我可以跑
user.avatar.attach(params[:file])
再次。但这会引发错误:
ActiveRecord::RecordNotSaved: Failed to remove the existing associated avatar_attachment. The record failed to save after its foreign key was set to nil.
这应该是什么意思?如何更改用户头像?
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-5 rails-activestorage