Sha256: 2e2a4faccf9249436fb2e2932d7027440d3e3afb5163f648f452683f3c1d0790

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

module Formol
  class Poll::Vote < ActiveRecord::Base
    #Security
    attr_protected :voter_id, :option_id
    
    #Associations
    belongs_to :option, :counter_cache  => true
    belongs_to :voter,  :class_name     => Formol.config.user_class
    
    has_one :poll, :through => :option
    
    #Validations
    validates :option,  :presence => true
    validates :voter,   :presence => true
    
    #Callbacks
    after_create  :increment_poll_votes_count
    after_destroy :decrement_poll_votes_count
    
    private
    
    #Callbacks methods
    
    def increment_poll_votes_count
      Formol::Poll.increment_counter(:votes_count, poll.id)
    end
    
    def decrement_poll_votes_count
      Formol::Poll.decrement_counter(:votes_count, poll.id)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formol-0.0.6 app/models/formol/poll/vote.rb
formol-0.0.5 app/models/formol/poll/vote.rb
formol-0.0.4 app/models/formol/poll/vote.rb