title: Ruby on Rails: What is the opposite of the build method? Or, can I destroy an object from memory before it's saved?
body: <p>In Rails 3, if I have used <code>build()</code> to build an object, is there a way to destroy it before the object was ever saved?</p>
  
  <p>The reason I need this is because I'm using a nested model form, with 3 generations of objects: Survey, which has many Questions, and Questions have many answers.</p>
  
  <p>In the controller, I use build to pre-populate questions and answers.</p>
  
  <p>The weird thing is, if the Survey model isn't valid, I re-render the page with the error messages, and the pre-built Questions appear in the form, but the not the Answers!</p>
  
  <p>(I'm using Simple Form, by the way, if that's important.)</p>
  
  <p>Anyway, I'd just destroy all the Questions before I rebuild them together with the answers, but how can you destroy the Questions if they haven't been saved to the database yet?</p>
  
  <p>In my controller:</p>
  
  <pre><code>4.times do
    question = @survey.questions.build
    @answers.each { |answer| question.answers.build(:label =&gt; option.label, :input_type =&gt; option.input_type, :available_options =&gt; option.available_options) }
  end
  </code></pre>
  
  <p>Any help would be greatly appreciated! Thanks!</p>