Permalink
Browse files

Replace Subclasses with Strategies: Step Five

* Pass strategy instead of subclass when only the strategy is needed
* Don't delegate strategy-specific behavior from subclasses
  • Loading branch information...
jferris committed Jan 31, 2013
1 parent 2bce7f7 commit c7a61dadfed53b9d93b578064d982f22d62f7b8d
@@ -3,10 +3,6 @@ class MultipleChoiceQuestion < Question

accepts_nested_attributes_for :options, reject_if: :all_blank

def options_for_form
submittable.options_for_form
end

def submittable
MultipleChoiceSubmittable.new(self)
end
@@ -2,10 +2,6 @@ class ScaleQuestion < Question
validates :maximum, presence: true
validates :minimum, presence: true

def steps
submittable.steps
end

def submittable
ScaleSubmittable.new(self)
end
@@ -1,3 +1,3 @@
<%= form.fields_for(:options, question.options_for_form) do |option_fields| -%>
<%= form.fields_for(:options, submittable.options_for_form) do |option_fields| -%>
<%= option_fields.input :text, label: 'Option' %>
<% end -%>
@@ -1,6 +1,10 @@
<%= simple_form_for question, as: :question, url: url do |form| -%>
<%= form.hidden_field :type %>
<%= form.input :title %>
<%= render "#{question.to_partial_path}_form", question: question, form: form %>
<%= render(
"#{question.to_partial_path}_form",
submittable: question.submittable,
form: form
) %>
<%= form.submit %>
<% end -%>
@@ -1,5 +1,5 @@
<ol>
<% scale_question.steps.each do |step| -%>
<% submittable.steps.each do |step| -%>
<li>
<%= submission_fields.radio_button :text, step %>
<%= submission_fields.label "text_#{step}", label: step %>
@@ -25,7 +25,11 @@
<li>
<%= form.fields_for "answers_attributes[#{question.id}]", Answer.new do |submission_fields| -%>
<%= submission_fields.label :text, label: question.title %>
<%= render question, submission_fields: submission_fields %>
<%= render(
question,
submission_fields: submission_fields,
submittable: question.submittable
) %>
<%= link_to 'Edit', edit_question_path(question) %>
<% end -%>
</li>

0 comments on commit c7a61da

Please sign in to comment.