Sha256: 195aa54c44f3b237db6e99b521688ac8cd69f87bd99550575858a50d8ba33656

Contents?: true

Size: 748 Bytes

Versions: 15

Compression:

Stored size: 748 Bytes

Contents

class TopicPostVote < ActiveRecord::Base

  belongs_to :user
  belongs_to :topic_post

  after_create :create_scores
  after_update :update_scores

  def create_scores
    self.topic_post.created_by_user.forum_points += self.score
    self.topic_post.created_by_user.forum_votes += 1
    self.topic_post.created_by_user.save
    self.topic_post.score += self.score
    self.topic_post.save
  end

  def update_scores
    return unless self.score_changed?

    self.topic_post.created_by_user.forum_points -= self.score_was
    self.topic_post.created_by_user.forum_points += self.score
    self.topic_post.created_by_user.save

    self.topic_post.score -= self.score_was
    self.topic_post.score += self.score
    self.topic_post.save
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
kit_cms-2.3.22 app/models/topic_post_vote.rb
kit_cms-2.3.20 app/models/topic_post_vote.rb
kit_cms-2.3.19 app/models/topic_post_vote.rb
kit_cms-2.3.18 app/models/topic_post_vote.rb
kit_cms-2.3.17 app/models/topic_post_vote.rb
kit_cms-2.3.16 app/models/topic_post_vote.rb
kit_cms-2.3.15 app/models/topic_post_vote.rb
kit_cms-2.3.14 app/models/topic_post_vote.rb
kit_cms-2.3.13 app/models/topic_post_vote.rb
kit_cms-2.3.11 app/models/topic_post_vote.rb
kit_cms-2.3.10 app/models/topic_post_vote.rb
kit_cms-2.3.9 app/models/topic_post_vote.rb
kit_cms-2.3.8 app/models/topic_post_vote.rb
kit_cms-2.3.7 app/models/topic_post_vote.rb
kit_cms-2.3.6 app/models/topic_post_vote.rb