我有
class Users < ActiveRecord::Base
belongs_to :team, touch: true
end
class Team < ActiveRecord::Base
has_many :users
before_save :update_popularity
before_update :update_popularity
def popularity
#secret algorythm
end
private
def update_popularity
# This is not called
end
end
User.first.name = 'John'
当我保存用户时,我也希望更新团队人气。但是,似乎没有调用before_filter?
有没有正确的方法呢?
答案 0 :(得分:0)
试试这个before_update :update_popularity
更新
在审核了touch
方法here的API文档后,他们会说:
请注意,不会执行任何验证,只会进行
after_touch
回调 执行。