我正试图获得一些.attribute_changed? ActiveRecord :: Dirty
的功能我按照这里的示例:http://api.rubyonrails.org/v3.2.16/classes/ActiveModel/Dirty.html
但我得到了:
ArgumentError (wrong number of arguments (3 for 0)):
app/models/appointment.rb:5:in `<class:Appointment>'
因为这一行:
define_attribute_methods [:at, :job_type, :length]
所以我尝试了NonPersistedAttributeMethods:https://stackoverflow.com/a/14467907/203915
但覆盖方法不起作用('at'返回nil,否则为
)我得到了什么:
def at
@at
end
def at=(val)
at_will_change! unless val == @at
@at = val
end