Class: Qe::ReferenceQuestion

Inherits:
Question show all
Defined in:
app/models/qe/reference_question.rb

Instance Attribute Summary

Attributes inherited from Question

#answers

Instance Method Summary collapse

Methods inherited from Question

#default_label?, #required?, #responses, #save_file, #save_response, #set_response, #validation_class

Methods inherited from Element

#all_elements, #duplicate, max_label_length, #position, #question?, #required?, #reuseable?, #set_position

Instance Method Details

#display_response(app = nil) ⇒ Object



33
34
35
# File 'app/models/qe/reference_question.rb', line 33

def display_response(app=nil)
  return response(app).to_s
end

#has_response?(app = nil) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'app/models/qe/reference_question.rb', line 24

def has_response?(app = nil)
  if app
    reference = response(app)
    reference && reference.valid?
  else
    ReferenceSheet.where(:question_id => id).count > 0
  end
end

#ptemplateObject

style format is detetermined in the views



38
39
40
# File 'app/models/qe/reference_question.rb', line 38

def ptemplate
  style 
end

#response(app = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/qe/reference_question.rb', line 7

def response(app=nil)
  return unless app
  # A reference is the same if the related_question_sheet corresponding to the question is the same
  reference = ReferenceSheet.find_by_applicant_answer_sheet_id_and_question_id(app.id, id)
  # if references.present?
  #   reference = references.detect {|r| r.question_id == id }
  #   # If they have another reference that matches this question id, don't go fishing for another one
  #   unless reference
  #     # If the question_id doesn't match, but the reference question is based on the same reference template (question sheet)
  #     # update the reference with the new question_id
  #     reference = references.detect {|r| r.question.related_question_sheet_id == related_question_sheet_id}
  #     reference.update_attribute(:question_id, id) if reference
  #   end
  # end
  reference || ReferenceSheet.create(:applicant_answer_sheet_id => app.id, :question_id => id) 
end