Sha256: 920f2c36cfb50d55f05ed0eb2b45487c76008c14da978a3d0774b3d24b9b5c7c

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

# ReferenceQuestion
# - a question that provides a fields to specify a reference
module Fe
  class ReferenceQuestion < Question

    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 = Fe::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 || Fe::ReferenceSheet.create(:applicant_answer_sheet_id => app.id, :question_id => id)
    end

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

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

    # which view to render this element?
    def ptemplate
      "fe/reference_#{style}"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fe-0.0.4 app/models/fe/reference_question.rb