All basic question types
This commit is contained in:
parent
3e1e5618ca
commit
4fe218166f
51 changed files with 760 additions and 92 deletions
23
app/controllers/questions_controller.rb
Normal file
23
app/controllers/questions_controller.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue