Class: ArPoll

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/ar_poll.rb

Overview

Schema information

Table name: ar_poll : Polls

id Integer id created_at Time created_at updated_at Time updated_at name String Unique poll name title String Title for the poll sub_text String Short description of the poll pre_display String pre_display operation String Operation performed on submit parameters String Aditional parameters for operation display String Select how fields are positioned on form css String CSS specific to this poll form String You can specified input items by providing form acording to rules of AgileRails form. valid_from DateTime Pole is valid from valid_to DateTime Pole is valid to captcha_type String Catpcha type name if captcha is used active Boolean active created_by Integer created_by updated_by Integer updated_by

ArPoll documents are used for different questionaries and formulars which can be accessed independent or connected with ArPage documents. Entry fields can be defined in related ar_poll_items table or as AgileRails form YAML style entered into form field.

Instance Method Summary collapse

Instance Method Details

#save_results(data) ⇒ Object

Save poll results to ArPollResults table

Params: data : Hash : Records hash (params)



62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/ar_poll.rb', line 62

def save_results(data)
  h = {}
  items = form.blank? ? ArPollItem.where(ar_poll_id: id) : YAML.load(self.form.gsub(' ', ' '))
  items.each do |item|
    next if %w(hidden_field submit_tag link_to comment).include?(item.field_type) # ignore
    next if item.try(:options).match('hidden') # also ignore

    h[ item['name'] ] = data[ item['name'] ]
  end
  ArPollResult.create(ar_poll_id: id, data: h.to_yaml)
end