Skip to content

Commit 80537af

Browse files
rubysclaude
andcommitted
Add questions display to person edit forms
Phase 4: Person Form for Answers - Created _questions.html.erb partial for person forms - Displays all applicable questions based on package and options - Renders radio buttons for radio-type questions - Renders textarea for textarea-type questions - Properly handles existing answers and new answer creation - Integrated into person form after options section - All tests passing (910 tests, 0 failures) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 28b4406 commit 80537af

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

app/views/people/_form.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,5 @@
132132

133133
<%= render partial: 'package', locals: { person: person } %>
134134
<%= render partial: 'options', locals: { form: form } %>
135+
<%= render partial: 'questions', locals: { form: form } %>
135136
<% end %>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="my-5" id="questions-section">
2+
<% applicable_questions = @person.applicable_questions %>
3+
<% if applicable_questions.any? %>
4+
<h3 class="font-bold text-xl mb-4">Questions</h3>
5+
6+
<% applicable_questions.each do |question| %>
7+
<% existing_answer = @person.answers.find_by(question_id: question.id) %>
8+
<% answer_index = existing_answer&.id || "new_#{question.id}" %>
9+
10+
<div class="my-4">
11+
<%= form.fields_for :answers, existing_answer || @person.answers.build(question: question) do |answer_form| %>
12+
<%= answer_form.hidden_field :question_id, value: question.id %>
13+
14+
<label class="block font-medium mb-2"><%= question.question_text %></label>
15+
16+
<% if question.question_type == 'radio' %>
17+
<div class="space-y-2">
18+
<% question.choices.each do |choice| %>
19+
<label class="flex items-center">
20+
<%= answer_form.radio_button :answer_value, choice,
21+
checked: existing_answer&.answer_value == choice,
22+
class: "mr-2" %>
23+
<%= choice %>
24+
</label>
25+
<% end %>
26+
</div>
27+
<% else %>
28+
<%= answer_form.text_area :answer_value,
29+
rows: 3,
30+
placeholder: "Enter your answer...",
31+
class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
32+
<% end %>
33+
<% end %>
34+
</div>
35+
<% end %>
36+
<% end %>
37+
</div>

0 commit comments

Comments
 (0)