title: How do I pass an incrementing counter into a partial when not rendering from an instance variable?
body: <p>I have a partial: <code>views/nodes/_node.html.erb</code>, which I render on any view like so:</p>
  
  <pre><code>&lt;%= render @nodes %&gt;
  </code></pre>
  
  <p>When I render it like that, per the Rails Guides, I can use <code>node_counter</code> within the partial as a counter to keep track of various elements within the partial (or say assign an ID that increments every time the partial is rendered).</p>
  
  <p>Now I want to use this same partial, but not rendered like that but rather like this:</p>
  
  <pre><code>&lt;%= render partial: "nodes/node", locals: {node: event.eventable} %&gt;
  </code></pre>
  
  <p>When I do that, I get this error:</p>
  
  <pre><code>undefined local variable or method `node_counter' for #&lt;#&lt;Class:0x007fa3b6ca9778&gt;:0x007fa3b58a60c8&gt;
  </code></pre>
  
  <p>That is because I never specified/passed <code>node_counter</code> as a local variable.</p>
  
  <p>So how do I specify <code>node_counter</code> to start at 0 and always increment every time this partial is rendered - if I can't do it the Rails Way?</p>
  
  <p>For reference, the Rails Guide says this:</p>
  
  <pre><code>Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by _counter. For example, if you're rendering @products, within the partial you can refer to product_counter to tell you how many times the partial has been rendered. This does not work in conjunction with the as: :value option.
  </code></pre>