问卷选择其他选项报错

dev_new_shixunsrepository
cxt 5 years ago
parent 1734ce2267
commit 6fbf7704f0

@ -46,9 +46,9 @@ 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 user_votes.find_vote_text.present? ques_vote = user_votes.find_by(poll_answer_id: ques_vote_id)
current_vote_text = user_votes.find_vote_text.first if ques_vote.present?
current_vote_text.update_attribute("vote_text", question_answer_text) ques_vote.update_attribute!("vote_text", question_answer_text)
else else
answer_option = { answer_option = {
:user_id => current_user.id, :user_id => current_user.id,
@ -56,7 +56,7 @@ class PollVotesController < ApplicationController
: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)
# 重新取一次poll_votes # 重新取一次poll_votes
user_votes = @poll_question.poll_votes.find_current_vote("user_id",current_user.id) user_votes = @poll_question.poll_votes.find_current_vote("user_id",current_user.id)
end end

Loading…
Cancel
Save