Module: SurveyingHelper

Included in:
SurveyingController
Defined in:
app/helpers/surveying_helper.rb

Instance Method Summary collapse

Instance Method Details

#answer_id_helper(answer) ⇒ Object



44
45
46
# File 'app/helpers/surveying_helper.rb', line 44

def answer_id_helper(answer)
  "answer_id_#{answer.id}"
end

#dependency_explanation_helper(question, response_set) ⇒ Object

Attempts to explain why this dependent question needs to be answered by referenced the dependent question and users response



82
83
84
85
86
87
88
89
# File 'app/helpers/surveying_helper.rb', line 82

def dependency_explanation_helper(question,response_set)
  trigger_responses = []
  dependent_questions = Question.find_all_by_id(question.dependency.dependency_conditions.map(&:question_id)).uniq
  response_set.responses.find_all_by_question_id(dependent_questions.map(&:id)).uniq.each do |resp|
    trigger_responses << resp.to_s
  end
  "&nbsp;&nbsp;You answered &quot;#{trigger_responses.join("&quot; and &quot;")}&quot; to the question &quot;#{dependent_questions.map(&:text).join("&quot;,&quot;")}&quot;"
end

#fields_for_radio(response, &block) ⇒ Object



61
62
63
# File 'app/helpers/surveying_helper.rb', line 61

def fields_for_radio(response, &block)
  fields_for("responses[#{response.question_id}]", response, :builder => SurveyFormBuilder, &block)
end

#fields_for_repeater_response(response, response_group, &block) ⇒ Object

Changes the response hash to accept response groups for repeater elements



57
58
59
# File 'app/helpers/surveying_helper.rb', line 57

def fields_for_repeater_response(response, response_group, &block)
  fields_for("response_groups[#{response.question_id}][#{response_group}][#{response.answer_id}]", response, :builder => SurveyFormBuilder, &block)
end

#fields_for_response(response, &block) ⇒ Object



52
53
54
# File 'app/helpers/surveying_helper.rb', line 52

def fields_for_response(response, &block)
  fields_for("responses[#{response.question_id}][#{response.answer_id}]", response, :builder => SurveyFormBuilder, &block)
end

#question_help_helper(question) ⇒ Object



48
49
50
# File 'app/helpers/surveying_helper.rb', line 48

def question_help_helper(question)
  question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
end

#question_id_helper(question) ⇒ Object



40
41
42
# File 'app/helpers/surveying_helper.rb', line 40

def question_id_helper(question)
  "question_#{question.id}"
end

#question_number_helper(number) ⇒ Object

Formats the question number the way we want, or not at all if number is nil



4
5
6
7
8
9
10
# File 'app/helpers/surveying_helper.rb', line 4

def question_number_helper(number)
  if number
    "#{number}<span style='padding-left:0.1em;'>)</span>" 
  else
    ""
  end
end

#question_text_postfix_helper(question_text = "") ⇒ Object Also known as: answer_text_postfix_helper

Parts of the question that go after the input element



24
25
26
27
28
29
30
31
# File 'app/helpers/surveying_helper.rb', line 24

def question_text_postfix_helper(question_text = "")
  splits = question_text.split("|")
  if splits.size > 1
    splits[1] 
  else
    "&nbsp;"
  end
end

#question_text_prefix_helper(question_text = "") ⇒ Object Also known as: answer_text_prefix_helper

splits the question text using the delimiter parts before the delim. go before the input element, parts after the delim. go after the input element



14
15
16
17
18
19
20
21
# File 'app/helpers/surveying_helper.rb', line 14

def question_text_prefix_helper(question_text = "")
  splits = question_text.split("|")
  unless splits[0].empty?
    splits[0] 
  else
    "&nbsp;"
  end      
end

#section_id_helper(section) ⇒ Object



36
37
38
# File 'app/helpers/surveying_helper.rb', line 36

def section_id_helper(section)
  "section_#{section.id}"
end

#section_next_helper(section) ⇒ Object



69
70
71
# File 'app/helpers/surveying_helper.rb', line 69

def section_next_helper(section)
  submit_tag("Next section &gt;&gt;", :name => section_submit_name_helper(section))
end

#section_previous_helper(section) ⇒ Object



73
74
75
# File 'app/helpers/surveying_helper.rb', line 73

def section_previous_helper(section)
  submit_tag("&lt;&lt; Previous section", :name => section_submit_name_helper(section))
end

#section_submit_helper(section) ⇒ Object



65
66
67
# File 'app/helpers/surveying_helper.rb', line 65

def section_submit_helper(section)
  submit_tag(section.title, :name => section_submit_name_helper(section))
end

#section_submit_name_helper(section, anchor_id = nil) ⇒ Object



77
78
79
# File 'app/helpers/surveying_helper.rb', line 77

def section_submit_name_helper(section, anchor_id = nil)
  "section[#{section.id}#{(anchor_id)? "_#{anchor_id}" : ""}]"
end