uses new answer model in user facing interface

This commit is contained in:
rgarcia
2017-10-04 17:45:51 +02:00
parent 461410a79d
commit 4aaf681d2d
8 changed files with 28 additions and 20 deletions

View File

@@ -8,8 +8,10 @@ class Poll::Answer < ActiveRecord::Base
validates :question, presence: true
validates :author, 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_question, ->(question_id) { where(question_id: question_id) }

View File

@@ -14,8 +14,8 @@ class Poll::Question < ActiveRecord::Base
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
has_many :comments, as: :commentable
has_many :answers
has_many :question_answers, class_name: 'Poll::Question::Answer', foreign_key: 'poll_question_id'
has_many :answers, class_name: 'Poll::Answer'
has_many :question_answers, class_name: 'Poll::Question::Answer'
has_many :partial_results
belongs_to :proposal

View File

@@ -1,5 +1,5 @@
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