脏(已更改)属性:从什么时候开始更改集字符串中的值(而不是对象)?
Dirty (changed) attributes: since when are the values in the changeset strings (instead of objects)?
我正在使用乐观锁定来防止人们互相覆盖竞争条件的变化。
自从我将 Rails 从 5.1
升级到 5.2
后,我的规格被打破了,我追踪到 changes
数组中的变化与文件上传相关的不再是 Uploader
元素,而是裸字符串。
之前:
[1] pry(#<User>)> change
=> [
[0] #<AvatarUploader:0x007fcc7117bc00 # Value before
[1] #<AvatarUploader:17bc0cc7100x997f # Current value
现在:
[1] pry(#<User>)> change
=> [
[0] "image.jpg", # Value before
[1] "avatar.png" # Current value
]
我该如何解决这个问题?
这个问题似乎与 CarrierWave 1.3.1
中有关脏检查的其他奇怪问题类似
尝试重新安装旧版本或尝试 2.0.0,但似乎他们尚未解决该问题。
我没有找到上述行为发生变化的原因,但我可以修复它。
之前的代码:
@user.changes.map do |attribute, change|
unless ['updated_at', 'lock_version'].include? attribute
StaleInfo.new resource: resource,
attribute: attribute,
value_before: change[0],
value_after: change[1]
end
end
现在编码:
@user.changes.map do |attribute, change|
unless ['updated_at', 'lock_version'].include? attribute
StaleInfo.new resource: resource,
attribute: attribute,
value_before: resource.class.find(resource.id).send(attribute),
value_after: resource.send(attribute)
end
end
虽然这种方式感觉很古怪,它需要一个额外的数据库查询(加载原始对象)。
我正在使用乐观锁定来防止人们互相覆盖竞争条件的变化。
自从我将 Rails 从 5.1
升级到 5.2
后,我的规格被打破了,我追踪到 changes
数组中的变化与文件上传相关的不再是 Uploader
元素,而是裸字符串。
之前:
[1] pry(#<User>)> change
=> [
[0] #<AvatarUploader:0x007fcc7117bc00 # Value before
[1] #<AvatarUploader:17bc0cc7100x997f # Current value
现在:
[1] pry(#<User>)> change
=> [
[0] "image.jpg", # Value before
[1] "avatar.png" # Current value
]
我该如何解决这个问题?
这个问题似乎与 CarrierWave 1.3.1
中有关脏检查的其他奇怪问题类似尝试重新安装旧版本或尝试 2.0.0,但似乎他们尚未解决该问题。
我没有找到上述行为发生变化的原因,但我可以修复它。
之前的代码:
@user.changes.map do |attribute, change|
unless ['updated_at', 'lock_version'].include? attribute
StaleInfo.new resource: resource,
attribute: attribute,
value_before: change[0],
value_after: change[1]
end
end
现在编码:
@user.changes.map do |attribute, change|
unless ['updated_at', 'lock_version'].include? attribute
StaleInfo.new resource: resource,
attribute: attribute,
value_before: resource.class.find(resource.id).send(attribute),
value_after: resource.send(attribute)
end
end
虽然这种方式感觉很古怪,它需要一个额外的数据库查询(加载原始对象)。