Added token to poll voters
This commit is contained in:
@@ -7,11 +7,11 @@ class Polls::QuestionsController < ApplicationController
|
|||||||
|
|
||||||
def answer
|
def answer
|
||||||
answer = @question.answers.find_or_initialize_by(author: current_user)
|
answer = @question.answers.find_or_initialize_by(author: current_user)
|
||||||
|
token = params[:token]
|
||||||
|
|
||||||
answer.answer = params[:answer]
|
answer.answer = params[:answer]
|
||||||
answer.token = params[:token]
|
|
||||||
answer.save!
|
answer.save!
|
||||||
answer.record_voter_participation
|
answer.record_voter_participation(token)
|
||||||
|
|
||||||
@answers_by_question_id = { @question.id => params[:answer] }
|
@answers_by_question_id = { @question.id => params[:answer] }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class PollsController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@questions = @poll.questions.for_render.sort_for_list
|
@questions = @poll.questions.for_render.sort_for_list
|
||||||
@token = poll_answer_author_token(@poll, current_user)
|
|
||||||
@answers_by_question_id = {}
|
@answers_by_question_id = {}
|
||||||
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
|
||||||
poll_answers.each do |answer|
|
poll_answers.each do |answer|
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ class Poll::Answer < ActiveRecord::Base
|
|||||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
||||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||||
|
|
||||||
def record_voter_participation
|
def record_voter_participation(token)
|
||||||
Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web")
|
Poll::Voter.find_or_create_by!(user: author, poll: poll, origin: "web") do |poll_voter|
|
||||||
|
poll_voter.token = token unless poll_voter.token.present?
|
||||||
|
poll_voter.token_seen_at = Time.now unless poll_voter.token_seen_at.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
class AddTokenToPollAnswer < ActiveRecord::Migration
|
|
||||||
def change
|
|
||||||
add_column :poll_answers, :token, :string
|
|
||||||
end
|
|
||||||
end
|
|
||||||
6
db/migrate/20171006145053_add_token_to_poll_voters.rb
Normal file
6
db/migrate/20171006145053_add_token_to_poll_voters.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class AddTokenToPollVoters < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :poll_voters, :token, :string
|
||||||
|
add_column :poll_voters, :token_seen_at, :date
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20171006102811) do
|
ActiveRecord::Schema.define(version: 20171006145053) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -592,7 +592,6 @@ ActiveRecord::Schema.define(version: 20171006102811) do
|
|||||||
t.string "answer"
|
t.string "answer"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "token"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "poll_answers", ["author_id"], name: "index_poll_answers_on_author_id", using: :btree
|
add_index "poll_answers", ["author_id"], name: "index_poll_answers_on_author_id", using: :btree
|
||||||
@@ -761,6 +760,8 @@ ActiveRecord::Schema.define(version: 20171006102811) do
|
|||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.string "origin"
|
t.string "origin"
|
||||||
t.integer "officer_id"
|
t.integer "officer_id"
|
||||||
|
t.string "token"
|
||||||
|
t.date "token_seen_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree
|
add_index "poll_voters", ["booth_assignment_id"], name: "index_poll_voters_on_booth_assignment_id", using: :btree
|
||||||
|
|||||||
Reference in New Issue
Block a user