Skip to content

Commit 8243493

Browse files
committed
Render views polymorphically
* Takes advantage of to_partial_path to render question collection * Removes Divergent Change smell from surveys/show.html.erb * Applies Replace Conditional with Polymorphism refactoring
1 parent 4f9bdfe commit 8243493

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ol>
2+
<% multiple_choice_question.options.each do |option| -%>
3+
<li>
4+
<%= submission_fields.radio_button :text, option.text, id: dom_id(option) %>
5+
<%= content_tag :label, option.text, for: dom_id(option) %>
6+
</li>
7+
<% end -%>
8+
</ol>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= submission_fields.text_field :text %>

example_app/app/views/questions/_question.html.erb

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ol>
2+
<% scale_question.steps.each do |step| -%>
3+
<li>
4+
<%= submission_fields.radio_button :text, step %>
5+
<%= submission_fields.label "text_#{step}", label: step %>
6+
</li>
7+
<% end -%>
8+
</ol>

example_app/app/views/surveys/show.html.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
<%= simple_form_for [@survey, @completion] do |form| -%>
2020
<ol>
2121
<% @questions.each do |question| -%>
22-
<%= render 'questions/question', question: question, form: form %>
22+
<%= form.fields_for "answers_attributes[#{question.id}]", Answer.new do |submission_fields| -%>
23+
<li>
24+
<%= submission_fields.label :text, label: question.title %>
25+
<%= render question, submission_fields: submission_fields %>
26+
</li>
27+
<% end -%>
2328
<% end -%>
2429
</ol>
2530
<%= form.submit 'Submit Answers' %>

0 commit comments

Comments
 (0)