forked from bofh/fetsite
update für questions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user