%
answers = question.answer.nil? ? [] : Array(question.answer['options'])
other_value = question.answer.nil? ? '' : question.answer['other']
%>
Select all that apply:
<% question.input_options.each do | option |
option_id = "#{option.parameterize}_#{question.to_i}"
checkbox_html = {class: "", id: option_id, data: { last: answers.include?(option) ? 'checked' : '' } }
%>
<%= check_box_tag('answer[answer_hash][options][]', option, answers.include?(option), checkbox_html) %>
<%= label_tag(option_id, option) %>
<%
end %>
<%
option_id = "other_#{question.to_i}"
checkbox_html = {class: "", id: option_id, data: { last: answers.include?('other') ? 'checked' : '' } }
text_html = {class: "", id: "text_#{option_id}", data: { last: other_value }}
%>
<%= check_box_tag('answer[answer_hash][options][]', 'other', answers.include?('other'), checkbox_html) %>
<%= label_tag(option_id, 'Other') %>
<%= text_field_tag 'answer[answer_hash][other]', other_value, text_html.merge(id: "#{option_id}_value") %>
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %>