non-summary question edit bug fix

This commit is contained in:
Mark Moser 2016-09-07 17:45:50 -05:00
parent 1ded44610b
commit eb2eb65219
2 changed files with 9 additions and 3 deletions

View File

@ -48,8 +48,8 @@ class QuizController < ApplicationController
def answer_params def answer_params
params.require(:answer).permit( params.require(:answer).permit(
:question_id, :question_id,
:answer_id,
:answer, :answer,
:answer_id,
answer_array: [], answer_array: [],
answer_hash: [:later, :html, :css, :js, :text, :other, options: []] answer_hash: [:later, :html, :css, :js, :text, :other, options: []]
) )
@ -61,8 +61,6 @@ class QuizController < ApplicationController
answer[:submitted] = params.key?(:submit) answer[:submitted] = params.key?(:submit)
answer[:answer] = answer_params[:answer_array] unless answer_params[:answer_array].nil? answer[:answer] = answer_params[:answer_array] unless answer_params[:answer_array].nil?
answer[:answer] = answer_params[:answer_hash].to_h unless answer_params[:answer_hash].nil? answer[:answer] = answer_params[:answer_hash].to_h unless answer_params[:answer_hash].nil?
answer.delete(:answer_array)
answer.delete(:answer_hash)
answer answer
end end

View File

@ -7,4 +7,12 @@ class Answer < ApplicationRecord
validates :candidate_id, presence: true validates :candidate_id, presence: true
validates :question_id, presence: true validates :question_id, presence: true
validates :answer, answer_format: true validates :answer, answer_format: true
# Throw away attributes
# convenience for form manipulation
def answer_array=(val); end
def answer_hash=(val); end
def answer_id=(val); end
end end