Sha256: f7473db2c36ec95da70856c677df9a6aa82825a26c1ec2c2217aae1f714fe0d3

Contents?: true

Size: 533 Bytes

Versions: 8

Compression:

Stored size: 533 Bytes

Contents

class Vote < ActiveRecord::Base
  validates_presence_of :user_id
  validates_presence_of :poll
  validates_presence_of :choice
  validates_uniqueness_of :user_id, :scope => :poll_id, :message => 'has already voted.'
    
  belongs_to :poll
  belongs_to :user
  belongs_to :choice, :counter_cache => true

  after_save :update_poll_votes_count
  
  def update_poll_votes_count
    votes_count = Choice.sum(:votes_count, :conditions => {:poll_id => self.poll_id})
    self.poll.votes_count = votes_count
    self.poll.save!
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
community_engine-2.3.2 app/models/vote.rb
community_engine-2.3.1 app/models/vote.rb
community_engine-2.3.0 app/models/vote.rb
community_engine-2.1.0 app/models/vote.rb
community_engine-2.0.0 app/models/vote.rb
community_engine-2.0.0.beta3 app/models/vote.rb
community_engine-2.0.0.beta2 app/models/vote.rb
community_engine-2.0.0.beta1 app/models/vote.rb