Skip to content

Instantly share code, notes, and snippets.

@netguru
Created November 19, 2008 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netguru/26488 to your computer and use it in GitHub Desktop.
Save netguru/26488 to your computer and use it in GitHub Desktop.
# =================
# = counter cache =
# =================
def after_save
self.update_counter_cache
end
def after_destroy
self.update_counter_cache
end
def update_counter_cache
self.user.update_attribute(:comments_count, self.user.comments.active.count)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment