title: Javascript in partial (Ruby on Rails)
body: <p>For example i have many comments rendered for the post.</p>
  
  <pre><code>&lt;%= render post.comments %&gt;
  </code></pre>
  
  <p>And in comments partial i have javascript wich will repeated so many times how many comments i have</p>
  
  <p><strong>_comment.html.erb</strong></p>
  
  <pre><code>&lt;div id="content_&lt;%= comment.id %&gt;"&gt;&lt;%= comment.content %&gt;&lt;/div&gt;
  &lt;scr​ipt&gt;$("content_&lt;%= comment.id %&gt;").click(function() { a​lert(​'content of comment &lt;%= comment.id %&gt;'​) });&lt;/sc​ript&gt;
  </code></pre>
  
  <p>What is the best way to avoid repeating javascript in source code?
  I tried to create *_comment.js.erb* file and put javascript there, but i don't understand how to make it work.</p>
  
  <p>Can anyone please explain me how to solve this problem?</p>