ruby-on-rails-4rubygemscounter-cache

Ruby on Rails - Counter cache doesn't work on production


I have added counter_cache to punching_bag gem. Everything works fine in Development ENV, but in Production ENV it doesn't do what it suppose to to.

I can see that punches_countcolumn is added into my posts table, but it doesn't increment the column.

Why this is happening and what can I do to fix it?


Solution

  • In Post model add following:

    attr_accessor :punches_count

    has_many :punches