title: One thing I don't understand about unobtrusive javascript
body: <p>I like the idea of separating functionality and this seems like the way of the future.</p>
  
  <p>But I'm used to integrating javascript inside loops in an embedded language like Rails ERB or PHP, where I can use the ID of a particular object as a reference in the javascript.</p>
  
  <p>Rails example:</p>
  
  <pre><code>&lt;% @comments.each do |comment| %&gt;
    &lt;div id="comment_&lt;%= comment.id %&gt;"&gt;
      &lt;%= comment.text %&gt;
      &lt;% link_to_function "Reply", "$('comment_#{comment.id}').insert(\"#{escape_javascript(render :partial =&gt; "_form", :locals =&gt; {:comment =&gt; comment})}\", {position: 'bottom'});" %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This isn't the only time I've ended up wanting to use Ruby methods inside javascript either.  I may want to use constants, or call other ruby methods on an object inside a loop <code>user.enabled?</code> or <code>user.full_name</code>, or render partials with those objects, etc.</p>
  
  <p>So how is this supposed to be accomplished if all the javascript is in another file or outside the loop?  I get that you can iterate through a bunch of divs in javascript using CSS selectors, but this doesn't allow me to call ruby methods on objects.  </p>
  
  <p>What am I missing?  Thanks!</p>