Class: FormSubmission
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FormSubmission
- Defined in:
- lib/generators/install/templates/app/models/form_submission.rb
Instance Method Summary collapse
Instance Method Details
#save_vars ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
42 43 44 |
# File 'lib/generators/install/templates/app/models/form_submission.rb', line 42 def schema FormSchema.where(:id => form_schema_id).first.data end |
#vars ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Object
38 39 40 |
# File 'lib/generators/install/templates/app/models/form_submission.rb', line 38 def vars=(hash) @_vars = hash end |
#vars_are_valid ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |