Skip to content

Commit

Permalink
Render views polymorphically
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jferris committed Nov 29, 2012
1 parent 4f9bdfe commit 8243493
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ol>
<% multiple_choice_question.options.each do |option| -%>
<li>
<%= submission_fields.radio_button :text, option.text, id: dom_id(option) %>
<%= content_tag :label, option.text, for: dom_id(option) %>
</li>
<% end -%>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= submission_fields.text_field :text %>
31 changes: 0 additions & 31 deletions example_app/app/views/questions/_question.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ol>
<% scale_question.steps.each do |step| -%>
<li>
<%= submission_fields.radio_button :text, step %>
<%= submission_fields.label "text_#{step}", label: step %>
</li>
<% end -%>
</ol>
7 changes: 6 additions & 1 deletion example_app/app/views/surveys/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
<%= simple_form_for [@survey, @completion] do |form| -%>
<ol>
<% @questions.each do |question| -%>
<%= render 'questions/question', question: question, form: form %>
<%= form.fields_for "answers_attributes[#{question.id}]", Answer.new do |submission_fields| -%>
<li>
<%= submission_fields.label :text, label: question.title %>
<%= render question, submission_fields: submission_fields %>
</li>
<% end -%>
<% end -%>
</ol>
<%= form.submit 'Submit Answers' %>
Expand Down

0 comments on commit 8243493

Please sign in to comment.