Sha256: 245cbadb71932dd4b68b42b354cfc2c258b2450be76800ffb1c79fde9070d5bf
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 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, prepend: true 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,"Responses 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
upgrade_surveyor_gui-0.1.3 | lib/surveyor_gui/models/survey_methods.rb |
upgrade_surveyor_gui-0.1.2 | lib/surveyor_gui/models/survey_methods.rb |