Sha256: 0545e89543b3bc5a1a989ea03d49389af95027ea294aac255eaf84e43842f543

Contents?: true

Size: 889 Bytes

Versions: 2

Compression:

Stored size: 889 Bytes

Contents

require_dependency 'tasuku/application_controller'

module Tasuku
  class Taskables::Questions::AnswersController < ApplicationController
    include Concerns::Redirectable

    before_action :set_question

    def create
      answer = Taskables::Question::Answer.new

      answer_params[:option_ids].each do |num|
        answer.votes.build option_id: num
      end

      answer.author = send Tasks.config.author

      respond_to do |format|
        if answer.save
          format.html { redirect_to redirect_path_for(answer) }
        else
          format.html { redirect_to :back, alert: answer.errors.full_messages.to_sentence }
        end
      end
    end

    private

    def answer_params
      params.require(:taskables_question_answer).permit(option_ids: [])
    end

    def set_question
      @question = Taskables::Question.find params[:question_id]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tasuku-0.1.1 app/controllers/tasuku/taskables/questions/answers_controller.rb
tasuku-0.1.0 app/controllers/tasuku/taskables/questions/answers_controller.rb