|
|
|
@ -16,9 +16,9 @@ class PollVotesController < ApplicationController
|
|
|
|
|
# 当前用户的当前答案,如果已存在,当再次点击的时候,取消答案,即删除该答案
|
|
|
|
|
current_vote_text = nil
|
|
|
|
|
|
|
|
|
|
if user_votes.find_vote_text.present?
|
|
|
|
|
current_vote_text = user_votes.find_vote_text.first
|
|
|
|
|
end
|
|
|
|
|
# if user_votes.find_vote_text.present?
|
|
|
|
|
# current_vote_text = user_votes.find_vote_text.first
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
vote_answer_params = {
|
|
|
|
|
:user_id => current_user.id,
|
|
|
|
@ -36,7 +36,6 @@ class PollVotesController < ApplicationController
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
if question_answer_text.present?
|
|
|
|
|
|
|
|
|
|
current_user_answer.update_attribute("vote_text", question_answer_text)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -48,7 +47,8 @@ class PollVotesController < ApplicationController
|
|
|
|
|
if question_answer_ids.present?
|
|
|
|
|
if question_answer_text.present? #有文字输入,但是不存在其他选项的
|
|
|
|
|
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)
|
|
|
|
|
else
|
|
|
|
|
answer_option = {
|
|
|
|
@ -59,6 +59,11 @@ class PollVotesController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
PollVote.create(answer_option)
|
|
|
|
|
end
|
|
|
|
|
# if current_vote_text.present? #已有其他输入文字的选项
|
|
|
|
|
# current_vote_text.update_attribute("vote_text", question_answer_text)
|
|
|
|
|
# else
|
|
|
|
|
#
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ea_ids = user_votes.pluck(:poll_answer_id)
|
|
|
|
@ -85,16 +90,20 @@ class PollVotesController < ApplicationController
|
|
|
|
|
user_votes.destroy_all
|
|
|
|
|
end
|
|
|
|
|
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)
|
|
|
|
|
else
|
|
|
|
|
user_votes.destroy_all
|
|
|
|
|
end
|
|
|
|
|
# if question_answer_text.present?
|
|
|
|
|
# user_votes.first.update_attribute("vote_text", question_answer_text)
|
|
|
|
|
# else
|
|
|
|
|
# user_votes.destroy_all
|
|
|
|
|
# end
|
|
|
|
|
else
|
|
|
|
|
PollVote.create(vote_answer_params)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@current_question_number = @poll_question.question_number
|
|
|
|
|
@current_question_necessary = @poll_question.is_necessary
|
|
|
|
|
#问答记录存在,且有值,才会有返回值。
|
|
|
|
|