Skip to content

Instantly share code, notes, and snippets.

@akhildave
Created March 4, 2015 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhildave/786342b179a627910ecc to your computer and use it in GitHub Desktop.
Save akhildave/786342b179a627910ecc to your computer and use it in GitHub Desktop.
question_type_methods.rb
SurveyorGui::Models::QuestionTypeMethods.module_eval do
def _process_answers_textbox(question, args)
is_exclusive = args[:is_exclusive]
other = args[:other]
is_comment = args[:comments]
omit_text = is_exclusive ? "\n"+args[:omit_text].to_s : ""
other_text = other ? "\n"+args[:other_text].to_s : ""
comments_text = is_comment ? "\n"+args[:comments_text].to_s : ""
answers_textbox = args[:answers_textbox]
################
#default answer is created with display order = nil.
#Remove it or update its display_order - fix.
question.answers.each_with_index {|a, index|
# if a.display_order.nil?
# a.display_order = 0
# else
# a.display_order = question.answers.size > 0 ? question.answers.last.display_order+1 : 0
# end
a.destroy
}
#################
updated_answers = TextBoxParser.new(
textbox: answers_textbox,
records_to_update: question.answers
)
updated_answers.update_or_create_records do |display_order, text|
_create_an_answer(display_order, text, question) if !display_order.nil?
end
_create_an_other_answer(question, other, other_text)
_create_an_omit_answer(question, is_exclusive, omit_text)
_create_a_comment_answer(question, is_comment, comments_text)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment