title: How do I prevent one partial from hijacking the local variables from another in the same view?
body: <p>So I have a <code>Question#Show.html.erb</code> that has the following:</p>
  
  <pre><code>  &lt;% @question.answers.each do |ans| %&gt;
      &lt;%= render partial: "questions/answer", locals: {ans: ans} %&gt;
    &lt;% end %&gt;
  
    &lt;div class="row"&gt;
      &lt;div class="col-lg-8 col-lg-offset-2"&gt;
          &lt;div class="ibox"&gt;
            &lt;div class="ibox-title"&gt;
                &lt;h5&gt;Your Refactor Suggestion&lt;/h5&gt;
            &lt;/div&gt;
  
            &lt;div class="ibox-content"&gt;
              &lt;%= render partial: "answers/form", locals: {answer: @question.answers.build(user: current_user)} %&gt;
            &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>This works fine.</p>
  
  <p>However, once I flip it (i.e. put the <code>div.class=row</code> that is currently at the bottom above the iterator at the top), I get some crazy errors.</p>
  
  <p>For instance, doing this:</p>
  
  <pre><code>  &lt;div class="row"&gt;
      &lt;div class="col-lg-8 col-lg-offset-2"&gt;
          &lt;div class="ibox"&gt;
            &lt;div class="ibox-title"&gt;
                &lt;h5&gt;Your Refactor Suggestion&lt;/h5&gt;
            &lt;/div&gt;
  
            &lt;div class="ibox-content"&gt;
              &lt;%= render partial: "answers/form", locals: {answer: @question.answers.build(user: current_user)} %&gt;
            &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;% @question.answers.each do |ans| %&gt;
      &lt;%= render partial: "questions/answer", locals: {ans: ans} %&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>Leads to this error:</p>
  
  <pre><code>ActionController::UrlGenerationError at /questions/42
  No route matches {:action=&gt;"vote_up", :controller=&gt;"answers", :id=&gt;nil} missing required keys: [:id]
  </code></pre>
  
  <p>Here is my <code>questions/_answer.html.erb</code> partial (truncated for brevity):</p>
  
  <pre><code>        &lt;%= link_to vote_up_answer_path(ans), method: :post do %&gt;
              &lt;i class="fa fa-chevron-up"&gt; &lt;/i&gt;
          &lt;% end %&gt;
          &lt;%= ans.cached_votes_total %&gt;
          &lt;%= link_to vote_down_answer_path(ans), method: :post do %&gt;
              &lt;i class="fa fa-chevron-down"&gt; &lt;/i&gt;
          &lt;% end %&gt;
              &lt;%= ans.body %&gt;
                          &lt;%= link_to ans.user.try(:email), user_path(ans.user) %&gt;
  </code></pre>
  
  <p>Here is my <code>answers/_form.html.erb</code> partial (also truncated for brevity):</p>
  
  <pre><code>&lt;%= simple_form_for(answer) do |f| %&gt;
    &lt;%= f.error_notification %&gt;
    &lt;%= f.input :question_id, as: :hidden %&gt;
    &lt;%= f.input :user_id, as: :hidden %&gt;
    &lt;div class="form-group"&gt;
      &lt;%= f.input_field :body, as: :text, class: "form-control", rows: 8 %&gt;
    &lt;/div&gt;
    &lt;div class="form-group"&gt;
      &lt;%= f.input_field :language, collection: ["ruby", "python", "php"], as: :select, selected: "ruby", class: "form-control" %&gt;
    &lt;/div&gt;
  
    &lt;div id="new-post-submission-button"&gt;
      &lt;%= f.button :submit, class: "btn btn-lg btn-primary pull-right" %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This is my <code>Questions#Show</code> controller:</p>
  
  <pre><code>  def show
      @question = Question.includes(:answers).find(params[:id])
    end
  </code></pre>
  
  <p>What could be causing that strange behavior?</p>