From 6fbf7704f035ac787cad1f840f0a1010d1373b33 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 11 Jan 2020 15:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E9=80=89=E6=8B=A9=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E9=80=89=E9=A1=B9=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/poll_votes_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 6dd62153d..6e4a9b470 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -46,9 +46,9 @@ class PollVotesController < ApplicationController if question_answer_ids.present? if question_answer_text.present? #有文字输入,但是不存在其他选项的 ques_vote_id = question_answer_ids.map(&:to_i).max - 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) + ques_vote = user_votes.find_by(poll_answer_id: ques_vote_id) + if ques_vote.present? + ques_vote.update_attribute!("vote_text", question_answer_text) else answer_option = { :user_id => current_user.id, @@ -56,7 +56,7 @@ class PollVotesController < ApplicationController :poll_answer_id => ques_vote_id, :vote_text => question_answer_text } - PollVote.create(answer_option) + PollVote.create!(answer_option) # 重新取一次poll_votes user_votes = @poll_question.poll_votes.find_current_vote("user_id",current_user.id) end