Permalink
Browse files

Introduce single table inheritence for Question

* Just introduces subclasses and type column
* Takes no advantage of polymorphism yet
  • Loading branch information...
jferris committed Nov 28, 2012
1 parent b535171 commit c18ebeb286443a7ddc8ad1599e8d5b36a13e3f6c
@@ -19,7 +19,7 @@ def create
private

def build_question
@question = @survey.questions.new(question_params)
@question = @survey.questions.new(question_params, without_protection: true)
end

def question_params
@@ -0,0 +1,2 @@
class MultipleChoiceQuestion < Question
end
@@ -0,0 +1,2 @@
class OpenQuestion < Question
end
@@ -3,6 +3,8 @@ class Question < ActiveRecord::Base

QUESTION_TYPES = %w(OpenQuestion MultipleChoiceQuestion ScaleQuestion).freeze

set_inheritance_column 'question_type'

validates :maximum, presence: true, if: :scale?
validates :minimum, presence: true, if: :scale?
validates :question_type, presence: true, inclusion: QUESTION_TYPES
@@ -0,0 +1,2 @@
class ScaleQuestion < Question
end
@@ -18,7 +18,9 @@

<%= simple_form_for [@survey, @completion] do |form| -%>
<ol>
<%= render @questions, form: form %>
<% @questions.each do |question| -%>
<%= render 'questions/question', question: question, form: form %>
<% end -%>
</ol>
<%= form.submit 'Submit Answers' %>
<% end -%>

0 comments on commit c18ebeb

Please sign in to comment.