Sha256: 3cf6c94f7eab31b22437c3bee7a77018f39a90f96a3fb36dd674171c44577274
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
# app/controllers/decidim/posts/user_answers_controller.rb module Decidim module Posts class UserAnswersController < ApplicationController def create answer_id = params[:answer_id].to_i checked = params[:checked].to_s.downcase == "true" ? true : false answer = Answer.find(answer_id) if checked if answer.question.single_choice? UserAnswer.where(decidim_user_id: current_user.id, decidim_posts_answer_id: answer.question.answers.pluck(:id)).destroy_all end UserAnswer.find_or_create_by(decidim_user_id: current_user.id, decidim_posts_answer_id: answer_id) else UserAnswer.where(decidim_user_id: current_user.id, decidim_posts_answer_id: answer_id).destroy_all end # get count of user_answers for all answers of the question user_answers_counts = {} answer.question.answers.each do |a| user_answers_counts[a.id] = UserAnswer.where(decidim_posts_answer_id: a.id).count end result = { user_answers: user_answers_counts, survey_responses_count: answer.question.post.survey_responses_count } render json: result, status: :ok end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
decidim-posts-1.0.0 | app/controllers/decidim/posts/user_answers_controller.rb |