Ruby on Rails latest stable (v4.2.1) - 0 notes - Class: ActiveRecord::CounterCache

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.2.13) is shown here.

These similar methods exist in v4.2.1:

increment_counter(counter_name, id) public

Increment a number field by one, usually representing a count.

This is used for caching aggregate values, so that they don’t need to be computed every time. For example, a DiscussionBoard may cache post_count and comment_count otherwise every time the board is shown it would have to run an SQL query to find how many posts and comments there are.


  • counter_name - The name of the field that should be incremented.

  • id - The id of the object that should be incremented.


# Increment the post_count column for the record with an id of 5
DiscussionBoard.increment_counter(:post_count, 5)
Show source
Register or log in to add new notes.