Skip to content

Instantly share code, notes, and snippets.

@salbito
Created October 21, 2010 22:59
Show Gist options
  • Save salbito/639543 to your computer and use it in GitHub Desktop.
Save salbito/639543 to your computer and use it in GitHub Desktop.
Answers new method
def new
@survey = Survey.find(params[:survey_id])
@questions = @survey.questions.all
@answers = @questions.map{|q| q.answers.build}
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @answer }
end
end
Answers View
= for answer in @answers$
%p= answer.answer_string$
%p= answer.question_id$
Html Output
<div id='body_con'>
<h1>New answer</h1>
<p></p>
<p>1</p>
<p></p>
<p>3</p>
<p></p>
<p>5</p>
<p></p>
<p>7</p>
<p></p>
<p>9</p>
[#&lt;Answer id: nil, answer_string: nil, created_at: nil, updated_at: nil, question_id: 1, user_id: nil&gt;, #&lt;Answer id: nil, answer_string: nil, created_at: nil, updated_at: nil, question_id: 3, user_id: nil&gt;, #&lt;Answer id: nil, answer_string: nil, created_at: nil, updated_at: nil, question_id: 5, user_id: nil&gt;, #&lt;Answer id: nil, answer_string: nil, created_at: nil, updated_at: nil, question_id: 7, user_id: nil&gt;, #&lt;Answer id: nil, answer_string: nil, created_at: nil, updated_at: nil, question_id: 9, user_id: nil&gt;]
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment