|
|
@ -30,26 +30,21 @@ class PollVotesController < ApplicationController
|
|
|
|
#begin
|
|
|
|
#begin
|
|
|
|
if question_type == 1
|
|
|
|
if question_type == 1
|
|
|
|
if user_votes.present? #用户曾经回答过的,答案选择不一样,否则新建
|
|
|
|
if user_votes.present? #用户曾经回答过的,答案选择不一样,否则新建
|
|
|
|
logger.info("########___________user_votes.present1111____________________#######")
|
|
|
|
|
|
|
|
current_user_answer = user_votes.first
|
|
|
|
current_user_answer = user_votes.first
|
|
|
|
if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录
|
|
|
|
if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录
|
|
|
|
logger.info("########___________user_votes.present22222____________________#######")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_user_answer.destroy
|
|
|
|
current_user_answer.destroy
|
|
|
|
PollVote.create(vote_answer_params)
|
|
|
|
user_votes = PollVote.new(vote_answer_params)
|
|
|
|
|
|
|
|
user_votes.save!
|
|
|
|
else
|
|
|
|
else
|
|
|
|
logger.info("########___________user_votes.present33333____________________#######")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if question_answer_text.present?
|
|
|
|
if question_answer_text.present?
|
|
|
|
logger.info("########___________user_votes.present4444444____________________#######")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_user_answer.update_attribute("vote_text", question_answer_text)
|
|
|
|
current_user_answer.update_attribute("vote_text", question_answer_text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
logger.info("########___________user_votes.present555555____________________#######")
|
|
|
|
user_votes = PollVote.new(vote_answer_params)
|
|
|
|
|
|
|
|
user_votes.save!
|
|
|
|
PollVote.create(vote_answer_params)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif question_type == 2 #多选题的话,答案应该是1个以上
|
|
|
|
elsif question_type == 2 #多选题的话,答案应该是1个以上
|
|
|
|
question_answer_ids = params[:poll_answer_id] ? params[:poll_answer_id] : [] #该答案的id
|
|
|
|
question_answer_ids = params[:poll_answer_id] ? params[:poll_answer_id] : [] #该答案的id
|
|
|
@ -107,6 +102,7 @@ class PollVotesController < ApplicationController
|
|
|
|
@current_question_necessary = @poll_question.is_necessary
|
|
|
|
@current_question_necessary = @poll_question.is_necessary
|
|
|
|
#问答记录存在,且有值,才会有返回值。
|
|
|
|
#问答记录存在,且有值,才会有返回值。
|
|
|
|
@current_question_status = 0
|
|
|
|
@current_question_status = 0
|
|
|
|
|
|
|
|
|
|
|
|
if user_votes.present?
|
|
|
|
if user_votes.present?
|
|
|
|
vote_answer_id = user_votes.pluck(:poll_answer_id).reject(&:blank?).size
|
|
|
|
vote_answer_id = user_votes.pluck(:poll_answer_id).reject(&:blank?).size
|
|
|
|
vote_text_count = user_votes.pluck(:vote_text).reject(&:blank?).size
|
|
|
|
vote_text_count = user_votes.pluck(:vote_text).reject(&:blank?).size
|
|
|
|