ruby-on-rails - 更改 CarrieWave 模型的文件名
问题描述
我有一个这样的 Rails 模型,使用 ImageUploader 继承CarrierWave::Uploader::Base
。
class Image < ApplicationRecord
mount_uploader :file, ImageUploader
end
我的应用程序中的一个错误导致images.file
列值与 GCS 中的实际文件名不匹配,所以我想这样做:
Image.first.file = "fixed_file_name.jpg"
Image.save
但Image#file
不返回其file
列值,而是返回CarrierWave::Uploader::Base
实例。
如何更新文件名,就像UPDATE ... SET ...
在 SQL 中一样?
解决方案
大概是这样的:User.where(id: 1).update_all(avatar: 'x.png')
推荐阅读
- c++ - 在cpp文件中定义一个类变量成员
- php - 在 Reactjs 应用程序中选中时使用复选框进行过滤
- html - 除非在页面顶部,否则导航链接将不起作用
- testing - 客户端事件自动测试的正确方法
- kubernetes-ingress - AKS 天蓝色/应用程序网关运行状况注释不会更新应用程序网关中的运行状况探测
- excel - 如何从多个表中检查和计算 excal 中的值
- javascript - 在 Reactjs 中检查整个组件中的用户不活动状态
- visual-studio-code - 设置优先级(用户、工作区、文件夹)
- python-imaging-library - 用枕头打开的图像不能给出错误
- c# - 注入 dbContext 时返回“找不到与给定参数匹配的构造函数”