Permalink
Browse files

Improving the HTML for the markup partial

  • Loading branch information...
1 parent 128c3fc commit 7f174e9211002c3c4ffd1a10e5773de6289cb4bf @adamcrown adamcrown committed Oct 19, 2011
Showing with 30 additions and 9 deletions.
  1. +11 −9 app/views/answerer/_answers.html.haml
  2. +19 −0 lib/ask/acts_as_answerer.rb
@@ -1,9 +1,11 @@
--answerer.all_questions.each do |question|
- -if(question.rhetorical?)
- %h3=question.name
- %p=question.instructions
- -else
- %dt=question.name
- -answerer.answers_to(question).each do |answer|
- -unless answer.answer.blank?
- %dd=answer.answer
+-raise 'You must pass in an "answerer" to use this partial' unless defined? answerer
+
+-answerer.questions_by_section.each do |section, questions|
+ -unless section.nil?
+ %h3= section.name
+ %p= section.instructions
+ %dl
+ -questions.each do |question|
+ %dt= question.name
+ -answerer.answers_to(question).each do |answer|
+ %dd= answer.answer
@@ -20,6 +20,25 @@ def find_question(question)
end
end
+ def questions_by_section
+ section = nil
+ questions = {}
+
+ asker.questions.order(:position).each do |question|
+ if question.is_a? FormSection
+ section = question
+ end
+
+ questions[section] ||= []
+
+ unless question.is_a? FormSection
+ questions[section] << question
+ end
+ end
+
+ questions
+ end
+
def answer_to(question)
return nil if question.nil?
if question.supports_multiple_answers?

0 comments on commit 7f174e9

Please sign in to comment.