Sha256: 56386d02cab25018182ec92dd522b3612eb5311890248dcfbf0475b3015a9ea8
Contents?: true
Size: 979 Bytes
Versions: 3
Compression:
Stored size: 979 Bytes
Contents
class Poll < ActiveRecord::Base acts_as_content_block has_many :responses, :class_name => "PollResponse" accepts_nested_attributes_for :responses, :allow_destroy => true validates_presence_of :question def total_votes self.responses.inject(0) { |sum, r| sum += r.votes } end def name question end # Overridden to make sure nested attributes (i.e. poll responses) will correctly update. def update_attributes(attributes) unless attributes[:responses_attributes].blank? logger.debug "Forcing update of poll so updated answers are saved." self.updated_at = Time.now # Force this block to update, regardless of what was submitted. else logger.debug "No poll attributes were submitted." end super(attributes) end # Overridden for purely debugging purposes. def different_from_last_draft? result = super logger.debug "Is this poll is different than the last draft? '#{result}'" result end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bcms_polling-1.0.3 | app/models/poll.rb |
bcms_polling-1.0.2 | app/models/poll.rb |
bcms_polling-1.0.0 | app/models/poll.rb |