entrance-exam/app/controllers/questions_controller.rb

27 lines
602 B
Ruby

class QuestionsController < ApplicationController
def answer
question = Question.find(params[:id])
@answer = Answer.find_or_initialize_by(question:)
send(:"handle_#{question.answer_kind}_answer")
end
private
def handle_simple_answer
@answer.update!(data: params[:value])
end
def handle_image_answer
@answer.image.attach(
io: StringIO.new(Base64.decode64(params[:data])),
filename: params[:filename],
content_type: params[:mimetype],
)
@answer.save!
end
def handle_politicians_answer
@answer.update!(data: params[:order])
end
end