class FormSubmission

Public Instance Methods

save_vars() click to toggle source
# File lib/generators/install/templates/app/models/form_submission.rb, line 47
def save_vars 
  FormVar.delete_all(:form_submission_id  => self.id)
  @_vars.each do |key,value|
    var = FormVar.new
    var.form_submission_id = self.id
    var.key = key
    var.value = value
    var.save
  end
end
schema() click to toggle source
# File lib/generators/install/templates/app/models/form_submission.rb, line 42
def schema
  FormSchema.where(:id => form_schema_id).first.data
end
vars() click to toggle source
# File lib/generators/install/templates/app/models/form_submission.rb, line 24
def vars
  if !@_vars.nil? 
     @_vars
  elsif self.id.nil?
    {}
  else
    @_vars = {}
    self.form_vars.each do |form_var|
      @_vars[form_var.key] = form_var.value
    end
    @_vars
  end
end
vars=(hash) click to toggle source
# File lib/generators/install/templates/app/models/form_submission.rb, line 38
def vars=(hash)
  @_vars = hash
end
vars_are_valid() click to toggle source
# File lib/generators/install/templates/app/models/form_submission.rb, line 9
def vars_are_valid 
  current_vars = self.vars
  JSON.parse(self.schema)['inputs'].each do |input|
    if input['type'] == 'textbox' || input['type'] == 'email' ||  input['type'] == 'textarea' || input['type'] == 'email'
      if current_vars[input['label']].strip == ""
        errors.add input['label'].to_sym, " can't be blank"
      elsif input['type'] == 'email' && !current_vars[input['label']].match(/^[^@]+@[^@]+$/)
        errors.add input['label'].to_sym, " is invalid"
      end
    end
  end
end