Reputation: 1490
Say, I have a model A
with attribute name
.
If I do this A.new(name: nil).name_changed?
, it will return false
.
How can I detect that the attribute was set, even if it change nothing?
Upvotes: 1
Views: 72
Reputation: 15788
Try something like:
class A < ActiveRecord::Base
attr_accessor :name_set
def name=(v)
@name_set = true
super(v)
end
end
Now you can query the object with the name_set
method.
Upvotes: 3