diff --git a/app/controllers/survey/choices_controller.rb b/app/controllers/survey/choices_controller.rb index 52ca750..1cc2696 100644 --- a/app/controllers/survey/choices_controller.rb +++ b/app/controllers/survey/choices_controller.rb @@ -16,7 +16,7 @@ class Survey::ChoicesController < ApplicationController @survey_choice = Survey::Choice.find(params[:id]) respond_to do |format| - format.html # show.html.erb + format.html {redirect_to @survey_choice.question} format.json { render json: @survey_choice } end end diff --git a/app/controllers/survey/questions_controller.rb b/app/controllers/survey/questions_controller.rb index e5ecbaf..e7d18b4 100644 --- a/app/controllers/survey/questions_controller.rb +++ b/app/controllers/survey/questions_controller.rb @@ -3,17 +3,14 @@ class Survey::QuestionsController < ApplicationController # GET /survey/questions.json def index @survey_questions = Survey::Question.all - respond_to do |format| format.html # index.html.erb format.json { render json: @survey_questions } end end def answer - @survey_question = Survey::Question.find(params[:id]) - - - @survey_question.do_answer(params[:survey_question][:selected],current_user) + @survey_question = Survey::Question.find(params[:id]) + @survey_question.do_answer(params[:survey_question][:selected],current_user) render :show end # GET /survey/questions/1 diff --git a/app/models/survey/question.rb b/app/models/survey/question.rb index 7f2a2d2..6bba056 100644 --- a/app/models/survey/question.rb +++ b/app/models/survey/question.rb @@ -13,18 +13,21 @@ class Survey::Question < ActiveRecord::Base end def do_answer(choice_ids, user) -unless user.nil? - cid=choice_ids.map{|c|c.to_i} - unless cid.empty? - Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all - cid.each do |c| - if self.choice_ids.include?(c) - a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i) - a.save + unless (user.nil? || choice_ids.nil? || choice_ids.empty?) + cid=choice_ids.map{|c|c.to_i} + if (Survey::Answer.where(user_id: user.id, choice_id: cid).count > 0 ) + found_ids=Survey::Answer.where(user_id: user.id, choice_id: cid).includes(:choice).pluck(:choice_id) + cid= cid - found_ids + Survey::Answer.where(user_id: user.id, choice_id: found_ids).delete_all + else + Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all + end + cid.each do |c| + if self.choice_ids.include?(c) + a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i) + a.save + end end - end end end end -end - diff --git a/app/views/survey/questions/_answeredquestion.html.erb b/app/views/survey/questions/_answeredquestion.html.erb index f281048..a95cad5 100644 --- a/app/views/survey/questions/_answeredquestion.html.erb +++ b/app/views/survey/questions/_answeredquestion.html.erb @@ -40,7 +40,8 @@ $(function () { }, labels: { overflow: 'justify' - } + }, + minTickInterval: 1 }, tooltip: { valueSuffix: ' votes' @@ -52,17 +53,6 @@ $(function () { } } }, - legend: { - layout: 'vertical', - align: 'right', - verticalAlign: 'top', - x: -40, - y: 80, - floating: true, - borderWidth: 1, - backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'), - shadow: true - }, credits: { enabled: false },