Class: Answer

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
lib/survey_constructor/generators/templates/models/answer.rb

Instance Method Summary collapse

Instance Method Details

#text_answerObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/survey_constructor/generators/templates/models/answer.rb', line 12

def text_answer
  return justification if question.text?

  array_answers = choices.order(:id).map do |c|
    placeholder = question.placeholder.blank? ? ', ' : ", #{question.placeholder} "
    if c.justifiable
      "#{c.value}#{placeholder}#{justification.capitalize}"
    else
      c.value
    end
  end
  array_answers.join(', ')
end