title: How to use Rails helpers in coffeescript js
body: <p>I don't quite understand how helpers work in the view / controllers.  I have never used them.</p>
  
  <p>My specific question is:  almost all of my views implement AJAX.  In most of my controllers, the <em>update.js.coffee</em> and <em>create.js.coffee</em> have some form of the following code:</p>
  
  <pre><code>jQuery -&gt;
    &lt;% if @product.errors.any? %&gt;
    error_info = '&lt;%= j(render :partial =&gt; "shared/errors", :locals =&gt; { :record =&gt; @product }) %&gt;'
    popup error_info
  
    &lt;% else %&gt;
  .
  .
  .
  </code></pre>
  
  <p>where <code>popup</code> is a javascript function to display some element.</p>
  
  <p>Is there a way to abstract this into a helper?  What is the best way to do this?  this code is almost exactly the same in every case, except the 2 uses of <code>@product</code> would of course be different depending on the model in question.</p>
  
  <p>If this isn't what helpers are used for, then 1)  what are they used for?  and 2)  what should I be using instead?</p>
  
  <p>Edit:  BONUS QUESTION:  actually, many of my new, create, edit, and update functions are similar across models.  How do you DRY this up? or do you just not worry about it?</p>