title: How to generate array for grouped_options_for_select based on models
body: <p>A product belogs_to category.
  A category has_many products</p>
  
  <p>I need a select tag that includes the optgroup tag. </p>
  
  <p>So basically, I need my HTML markup to something similar to pseudo code:</p>
  
  <pre><code>&lt;select name="product" class="products"&gt;
    &lt;option value=""&gt;&lt;/option&gt;
    &lt;optgroup label="Cheese"&gt;
      &lt;option value="1"&gt;cheese 1&lt;/option&gt;
      &lt;option value="2"&gt;cheese 2&lt;/option&gt;
      &lt;option value="3"&gt;cheese 3&lt;/option&gt;
    &lt;/optgroup&gt;
    &lt;optgroup label="Juices"&gt;
      &lt;option value="3"&gt;juice 1&lt;/option&gt;
      &lt;option value="4"&gt;juice 2&lt;/option&gt;
      &lt;option value="5"&gt;juice 3&lt;/option&gt;
    &lt;/optgroup&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Based on my models, how would I generate the array to put into <strong>grouped_options_for_select</strong>? For example, what is the best approach to generate <strong>grouped_options</strong>?</p>
  
  <pre><code>&lt;%= select_tag 'product', grouped_options_for_select(grouped_options), :include_blank =&gt; true , :id =&gt; nil, :class =&gt; 'product' %&gt;
  </code></pre>