title: How to dynamically add select menu option in Rails
body: <p>Does anyone know if there is a simple solution to dynamically adding new options to a select menu in a form in Rails?</p>
  
  <p>The Dynamic Forms railscast (<a href="http://railscasts.com/episodes/403-dynamic-forms" rel="nofollow">http://railscasts.com/episodes/403-dynamic-forms</a>) is focused on dynamically filtering a second selet menu based on the selection made in another select menu which is not what I am looking for. I am looking for a solution where the form contains only one select menu and new options can be added to it on the form.</p>
  
  <p>I feel the solution may be similar to that touched upon in the Nested Model Form railscast (<a href="http://railscasts.com/episodes/196-nested-model-form-revised" rel="nofollow">http://railscasts.com/episodes/196-nested-model-form-revised</a>) but in that example the form must be submitted before the values are updated in the database. I would like the user to be able to add a new select menu option and then continue with the rest of the form before submitting it.</p>
  
  <p>At this stage I would also like to avoid using the railscast jquery autocomplete solution as this uses a text field rather than a select menu.</p>
  
  <p>Currently I see the solution as having a "Add New" button next to the select menu. When the button is clicked a Modal is opened that allows the user to enter the new select menu option and then save (update the database), the modal is closed and the form is updated. I'm just wondering whether an existing elegant solution is already out there.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks. </p>
  
  <p>UPDATE:</p>
  
  <p>I haven't created any code to implement this yet but here is my form:</p>
  
  <pre><code>&lt;%= simple_form_for @other, :html =&gt; { :class =&gt; 'form-horizontal' } do |f| %&gt;  
  &lt;fieldset&gt;
    &lt;%= f.error_notification %&gt;           
    &lt;%= f.association :other_type, :include_blank =&gt; false %&gt;      
    &lt;%= f.input :cost%&gt;
    &lt;%= f.input :invoice %&gt;             
    &lt;%= f.input :notes, :input_html =&gt; {:class =&gt; "row-fluid"} %&gt;
  &lt;%= f.error :base %&gt;
  &lt;div id="eze_form_actions" class="form-actions"&gt;
    &lt;%= f.submit nil, :class =&gt; 'btn btn-primary' %&gt;
    &lt;%= link_to 'Cancel', others_path, :class =&gt; 'btn' %&gt;
  &lt;/div&gt;
  &lt;/fieldset&gt;    
  &lt;% end %&gt;
  </code></pre>