【发布时间】:2019-10-02 23:44:15
【问题描述】:
我们在 Rails 5.2 应用程序中使用 activerecord-typedstore gem。除了 after 回调中的“脏属性”方法外,一切都很好。根据 gem 的页面,它应该适用于 Rails 5.2,但有一种简单的方法可以重现该问题
我自己没有找到解决方法,所以我在 gem 的 github 上发布了一个问题:https://github.com/byroot/activerecord-typedstore/issues/78
这个例子演示了这个问题:
class Profile < ApplicationRecord
typed_store :properties do |p|
p.string :phone
end
after_save :debug
def debug
puts "saved_change_to_phone #{saved_change_to_phone.inspect}"
end
end
p = Profile.create(phone: "123")
p.save
p = Profile.last
p.phone = "456"
p.save
# Displays:
# saved_change_to_phone nil
是否可以在 after 回调中获得标准 Rails 5.2 存储属性的行为?或者也许我可以使用另一种 gem?
【问题讨论】:
标签: ruby-on-rails activerecord ruby-on-rails-5 ruby-on-rails-5.2