uses new answer model in user facing interface
This commit is contained in:
@@ -8,8 +8,10 @@ class Poll::Answer < ActiveRecord::Base
|
|||||||
validates :question, presence: true
|
validates :question, presence: true
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
validates :answer, presence: true
|
validates :answer, presence: true
|
||||||
validates :answer, inclusion: { in: ->(a) { a.question.valid_answers }},
|
|
||||||
unless: ->(a) { a.question.blank? }
|
# temporary skipping validation, review when removing valid_answers
|
||||||
|
# validates :answer, inclusion: { in: ->(a) { a.question.valid_answers }},
|
||||||
|
# unless: ->(a) { a.question.blank? }
|
||||||
|
|
||||||
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) }
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ class Poll::Question < ActiveRecord::Base
|
|||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :answers
|
has_many :answers, class_name: 'Poll::Answer'
|
||||||
has_many :question_answers, class_name: 'Poll::Question::Answer', foreign_key: 'poll_question_id'
|
has_many :question_answers, class_name: 'Poll::Question::Answer'
|
||||||
has_many :partial_results
|
has_many :partial_results
|
||||||
belongs_to :proposal
|
belongs_to :proposal
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Poll::Question::Answer < ActiveRecord::Base
|
class Poll::Question::Answer < ActiveRecord::Base
|
||||||
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'poll_question_id'
|
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<%= render 'shared/errors', resource: @answer %>
|
<%= render 'shared/errors', resource: @answer %>
|
||||||
|
|
||||||
<%= f.hidden_field :poll_question_id, value: @question.id %>
|
<%= f.hidden_field :question_id, value: @question.id %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
<div class="poll-question-answers">
|
<div class="poll-question-answers">
|
||||||
<% if can? :answer, question %>
|
<% if can? :answer, question %>
|
||||||
<% question.valid_answers.each do |answer| %>
|
<% question.question_answers.each do |answer| %>
|
||||||
<% if @answers_by_question_id[question.id] == answer %>
|
<% if @answers_by_question_id[question.id] == answer.title %>
|
||||||
<span class="button answered" title="<%= t("poll_questions.show.voted", answer: answer)%>">
|
<span class="button answered"
|
||||||
<%= answer %>
|
title="<%= t("poll_questions.show.voted", answer: answer)%>">
|
||||||
|
<%= answer.title %>
|
||||||
</span>
|
</span>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to answer,
|
<%= link_to answer.title,
|
||||||
answer_question_path(question, answer: answer),
|
answer_question_path(question, answer: answer.title),
|
||||||
method: :post,
|
method: :post,
|
||||||
remote: true,
|
remote: true,
|
||||||
title: t("poll_questions.show.vote_answer", answer: answer),
|
title: t("poll_questions.show.vote_answer", answer: answer.title),
|
||||||
class: "button secondary hollow" %>
|
class: "button secondary hollow" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<% question.valid_answers.each do |answer| %>
|
<% question.question_answers.each do |answer| %>
|
||||||
<span class="button secondary hollow disabled"><%= answer %></span>
|
<span class="button secondary hollow disabled"><%= answer.title %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class RenamePollQuestionIdToQuestionId < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
rename_column :poll_question_answers, :poll_question_id, :question_id
|
||||||
|
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: 20171004025903) do
|
ActiveRecord::Schema.define(version: 20171004151553) 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"
|
||||||
@@ -671,10 +671,10 @@ ActiveRecord::Schema.define(version: 20171004025903) do
|
|||||||
create_table "poll_question_answers", force: :cascade do |t|
|
create_table "poll_question_answers", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.integer "poll_question_id"
|
t.integer "question_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "poll_question_answers", ["poll_question_id"], name: "index_poll_question_answers_on_poll_question_id", using: :btree
|
add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree
|
||||||
|
|
||||||
create_table "poll_questions", force: :cascade do |t|
|
create_table "poll_questions", force: :cascade do |t|
|
||||||
t.integer "proposal_id"
|
t.integer "proposal_id"
|
||||||
@@ -1152,7 +1152,7 @@ ActiveRecord::Schema.define(version: 20171004025903) do
|
|||||||
add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id"
|
add_foreign_key "poll_partial_results", "poll_officer_assignments", column: "officer_assignment_id"
|
||||||
add_foreign_key "poll_partial_results", "poll_questions", column: "question_id"
|
add_foreign_key "poll_partial_results", "poll_questions", column: "question_id"
|
||||||
add_foreign_key "poll_partial_results", "users", column: "author_id"
|
add_foreign_key "poll_partial_results", "users", column: "author_id"
|
||||||
add_foreign_key "poll_question_answers", "poll_questions"
|
add_foreign_key "poll_question_answers", "poll_questions", column: "question_id"
|
||||||
add_foreign_key "poll_questions", "polls"
|
add_foreign_key "poll_questions", "polls"
|
||||||
add_foreign_key "poll_questions", "proposals"
|
add_foreign_key "poll_questions", "proposals"
|
||||||
add_foreign_key "poll_questions", "users", column: "author_id"
|
add_foreign_key "poll_questions", "users", column: "author_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user