I am trying to use the counter_cache but it’s not updated…
class Proposal < ActiveRecord::Base
has_many :ratings, :dependent => :destroy
(I have defined a ratings_count column (default value 0) in my proposals
table)
class Rating < ActiveRecord::Base
belongs_to :user, :foreign_key => ‘user_id’
belongs_to :proposal, :foreign_key => ‘proposal_id’, :counter_cache =>
true
proposal_controller
def add_new_rating
…
@proposal = Proposal.find_by_id(params[:id].to_i)
@proposal.ratings.create(:user => current_user, :comment => @comment,
:value => @notation)
@ proposal.update_attribute(:total_value , @total_value)
the rating record is correctly created…
the proposal record total_value attribute is correctly updated, but the
counter ‘ratings_count’ is not incremented