我有一个activerecord模型。我想知道更新调用后有多少属性发生了变化。
这是我的模型代码
class User < ActiveRecord::Base
belongs_to :first_profile,:class_name => 'Profile',:foreign_key => :first_profile_id
accepts_nested_attributes_for :first_profile
attr_accessible :first_profile_attributes
end
class Profile < ActiveRecord::Base
belongs_to :user, :class_name => User
before_update :perform_task
end
当我更新或保存用户模型时,它首先保存的配置文件模型,当我在perform_task函数内时,我得到空的attributes_changes哈希。我试过使用published_changed但是我得到了未定义的函数错误。
由于
答案 0 :(得分:0)
请尝试published_changed?
。