问卷的简答题回答bug修复

problem_set
SylorHuang 5 years ago
parent c4d67c3948
commit 266fcfc4c7

@ -16,9 +16,9 @@ class PollVotesController < ApplicationController
# 当前用户的当前答案,如果已存在,当再次点击的时候,取消答案,即删除该答案 # 当前用户的当前答案,如果已存在,当再次点击的时候,取消答案,即删除该答案
current_vote_text = nil current_vote_text = nil
if user_votes.find_vote_text.present? # if user_votes.find_vote_text.present?
current_vote_text = user_votes.find_vote_text.first # current_vote_text = user_votes.find_vote_text.first
end # end
vote_answer_params = { vote_answer_params = {
:user_id => current_user.id, :user_id => current_user.id,
@ -36,7 +36,6 @@ class PollVotesController < ApplicationController
else else
if question_answer_text.present? if question_answer_text.present?
current_user_answer.update_attribute("vote_text", question_answer_text) current_user_answer.update_attribute("vote_text", question_answer_text)
end end
end end
@ -48,17 +47,23 @@ class PollVotesController < ApplicationController
if question_answer_ids.present? if question_answer_ids.present?
if question_answer_text.present? #有文字输入,但是不存在其他选项的 if question_answer_text.present? #有文字输入,但是不存在其他选项的
ques_vote_id = question_answer_ids.map(&:to_i).max ques_vote_id = question_answer_ids.map(&:to_i).max
if current_vote_text.present? #已有其他输入文字的选项 if user_votes.find_vote_text.present?
current_vote_text = user_votes.find_vote_text.first
current_vote_text.update_attribute("vote_text", question_answer_text) current_vote_text.update_attribute("vote_text", question_answer_text)
else else
answer_option = { answer_option = {
:user_id => current_user.id, :user_id => current_user.id,
:poll_question_id => @poll_question.id, :poll_question_id => @poll_question.id,
:poll_answer_id => ques_vote_id, :poll_answer_id => ques_vote_id,
:vote_text => question_answer_text :vote_text => question_answer_text
} }
PollVote.create(answer_option) PollVote.create(answer_option)
end end
# if current_vote_text.present? #已有其他输入文字的选项
# current_vote_text.update_attribute("vote_text", question_answer_text)
# else
#
# end
end end
ea_ids = user_votes.pluck(:poll_answer_id) ea_ids = user_votes.pluck(:poll_answer_id)
@ -85,12 +90,14 @@ class PollVotesController < ApplicationController
user_votes.destroy_all user_votes.destroy_all
end end
else #主观题的输入 else #主观题的输入
if current_vote_text.present? # current_vote_text = user_votes.find_vote_text
if question_answer_text.present? if user_votes.present?
user_votes.first.update_attribute("vote_text", question_answer_text) user_votes.first.update_attribute("vote_text", question_answer_text)
else # if question_answer_text.present?
user_votes.destroy_all # user_votes.first.update_attribute("vote_text", question_answer_text)
end # else
# user_votes.destroy_all
# end
else else
PollVote.create(vote_answer_params) PollVote.create(vote_answer_params)
end end

@ -13,7 +13,7 @@ module PollsHelper
end end
def poll_votes_count(votes,user_ids) def poll_votes_count(votes,user_ids)
votes.find_current_vote("user_id",user_ids.uniq).size votes.find_current_vote("user_id",user_ids.uniq).reject(&:blank?).size
end end
#公用tab页的相关信息 #公用tab页的相关信息

Loading…
Cancel
Save