Sha256: fd8c4ce2833493f33011a259ecac5956772108109b68d670e5be794903c0bd6b
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
module SurveyorGui module Models module SurveyMethods def self.included(base) base.extend Surveyor::Models::SurveyMethods base.send :attr_accessible, :title, :access_code, :template, :survey_sections_attributes if defined? ActiveModel::MassAssignmentSecurity base.send :has_many, :survey_sections, :dependent => :destroy base.send :accepts_nested_attributes_for, :survey_sections, :allow_destroy => true base.send :validate, :no_responses base.send :before_destroy, :no_responses end #don't let a survey be deleted or changed if responses have been submitted #to ensure data integrity def no_responses if self.id #this will be a problem if two people are editing the survey at the same time and do a survey preview - highly unlikely though. self.response_sets.where('test_data = ?',true).each {|r| r.destroy} end if !template && response_sets.count>0 errors.add(:base,"Reponses have already been collected for this survey, therefore it cannot be modified. Please create a new survey instead.") return false end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems