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