Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
说,我有一个A带有属性的模型name。
A
name
如果我这样做A.new(name: nil).name_changed?,它将返回false。
A.new(name: nil).name_changed?
false
我如何检测到该属性已设置,即使它没有任何改变?
尝试类似:
class A < ActiveRecord::Base attr_accessor :name_set def name=(v) @name_set = true super(v) end end
现在您可以使用该name_set方法查询对象。
name_set