jquery .each and rails
<p>I'm trying to translate this script to jQuery. See rails casts <a href="http://railscasts.com/episodes/88-dynamic-select-menus" rel="nofollow">#88</a></p>

<pre><code>var colors = new Array();
&lt;%= for color in @colors %&gt;
  colors.push(new Array(&lt;%= colot.product_id %&gt;, '&lt;%= color.name %&gt;', &lt;%= color.id %&gt;));
&lt;% end %&gt;

function productSelected() {
  product_id = $('order_items_attributes_0_product_id').val();
  options = $('item_color_id').options;
  colors.each(function(color) {
    if (color[0] == product_id) {
      options[options.length] = new Option(color[1], color[2]);
    }
  });
  if (options.length == 1) {
    $('color_field').hide();
  } else {
    $('color_field').show();
  }
}

$(document).ready(function() {
  productSelected();
  $('order_items_attributes_0_product_id').change(productSelected);
});
</code></pre>

<p>Firebug says </p>

<pre><code>TypeError: 'undefined' is not a function (evaluating 'colors.each(function(color) {
    if (color[0] == product_id) {
      options[options.length] = new Option(color[1], color[2]);
    }
  })')
</code></pre>

<p>Also the ruby code is no longer allowed in 3.1.1 js files (under assets)? It also complains about <code>SyntaxError: Unexpected token '&lt;'</code></p>
