update für questions

This commit is contained in:
Andreas Stephanides
2015-07-31 18:32:36 +02:00
parent 8a867b72a3
commit cd5f415ca1
4 changed files with 19 additions and 29 deletions

View File

@@ -16,7 +16,7 @@ class Survey::ChoicesController < ApplicationController
@survey_choice = Survey::Choice.find(params[:id]) @survey_choice = Survey::Choice.find(params[:id])
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html {redirect_to @survey_choice.question}
format.json { render json: @survey_choice } format.json { render json: @survey_choice }
end end
end end

View File

@@ -3,7 +3,6 @@ class Survey::QuestionsController < ApplicationController
# GET /survey/questions.json # GET /survey/questions.json
def index def index
@survey_questions = Survey::Question.all @survey_questions = Survey::Question.all
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render json: @survey_questions } format.json { render json: @survey_questions }
@@ -11,8 +10,6 @@ class Survey::QuestionsController < ApplicationController
end end
def answer def answer
@survey_question = Survey::Question.find(params[:id]) @survey_question = Survey::Question.find(params[:id])
@survey_question.do_answer(params[:survey_question][:selected],current_user) @survey_question.do_answer(params[:survey_question][:selected],current_user)
render :show render :show
end end

View File

@@ -13,10 +13,15 @@ class Survey::Question < ActiveRecord::Base
end end
def do_answer(choice_ids, user) def do_answer(choice_ids, user)
unless user.nil? unless (user.nil? || choice_ids.nil? || choice_ids.empty?)
cid=choice_ids.map{|c|c.to_i} cid=choice_ids.map{|c|c.to_i}
unless cid.empty? 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 Survey::Answer.where(user_id: user.id, choice_id: self.choice_ids).delete_all
end
cid.each do |c| cid.each do |c|
if self.choice_ids.include?(c) if self.choice_ids.include?(c)
a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i) a=Survey::Answer.new(user_id: user.id, choice_id: c.to_i)
@@ -26,5 +31,3 @@ unless user.nil?
end end
end end
end end
end

View File

@@ -40,7 +40,8 @@ $(function () {
}, },
labels: { labels: {
overflow: 'justify' overflow: 'justify'
} },
minTickInterval: 1
}, },
tooltip: { tooltip: {
valueSuffix: ' votes' 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: { credits: {
enabled: false enabled: false
}, },