Rails Updating Nested Model Collection Select
        Posted  
        
            by Timothy
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Timothy
        
        
        
        Published on 2010-06-10T15:21:06Z
        Indexed on 
            2010/06/10
            15:22 UTC
        
        
        Read the original article
        Hit count: 294
        
ruby-on-rails
I have a contrived nested Rails form like the following
  <% form_for @a do |fa| %>
    <% fa.fields_for :b do |fb| %>
      <% fb.fields_for :c do |fc| %>
        <%= fc.label :option_id %>
        <%= fc.collection_select :option_id, ModelD.all(:select => "id, name"), :id, :name %>
      <% end %>
    <% end %>
  <% end %>
and then somewhere else on the same page I have a remote form
  <% remote_form_for :modeld, ModelD.new, :url => new_modeld_path, :html => {:method => 'post'} do |f| %>
    <%= f.label :name %>
    <%= f.textarea :name %>
    <%= f.submit "Create" %>
  <% end %>
Is there any way I could update all the collection selects in the first form using Ajax when I submit the second form? There are an arbitrary number of collection selects.
© Stack Overflow or respective owner