ruby on rails - Nested form accepts_nested_attributes_for giving dynamic Array - Rails4 -
i working on rails4 nested form, accepts_nested_attributes_for can able generate nested form giving dynamic array the form when inspect form.
<input type="text" name="event_venue[event_contact_details_attributes][1403763304978][name]" id="event_venue_event_contact_details_attributes_1403763304978_name" class="form-control">
but should be,
<input type="text" name="event_venue[event_contact_details_attributes][1][name]" id="event_venue_event_contact_details_attributes_1_name" class="form-control"
>
<div class="formwrapper"> <div class="col-md-6"> <div class="form-group"> <label for="exampleinputemail1">name</label> <input type="text" name="event_venue[event_contact_details_attributes][1403764358820][name]" id="event_venue_event_contact_details_attributes_1403764358820_name" class="form-control"> </div> <div class="form-group"> <label for="exampleinputemail1">phone</label> <input type="text" name="event_venue[event_contact_details_attributes][1403764358820][telephone]" id="event_venue_event_contact_details_attributes_1403764358820_telephone" class="form-control"> </div> <div class="form-group"> <label for="exampleinputemail1">email</label> <input type="text" name="event_venue[event_contact_details_attributes][1403764358820][email]" id="event_venue_event_contact_details_attributes_1403764358820_email" class="form-control"> </div> <div class="clearfix"></div> <input type="hidden" value="false" name="event_venue[event_contact_details_attributes][1403764358820][_destroy]" id="event_venue_event_contact_details_attributes_1403764358820__destroy"><a onclick="remove_fields(this); return false;" href="#">remove</a> </div> </div>
can me out missing things...!!!
in first nested form set it's coming right,
<div class="formwrapper"> <div class="col-md-6"> <div class="form-group"> <label for="exampleinputemail1">name</label> <input type="text" value="as" name="event_venue[event_contact_details_attributes][0][name]" id="event_venue_event_contact_details_attributes_0_name" class="form-control"> </div> <div class="form-group"> <label for="exampleinputemail1">phone</label> <input type="text" value="as" name="event_venue[event_contact_details_attributes][0][telephone]" id="event_venue_event_contact_details_attributes_0_telephone" class="form-control"> </div> <div class="form-group"> <label for="exampleinputemail1">email</label> <input type="text" value="as" name="event_venue[event_contact_details_attributes][0][email]" id="event_venue_event_contact_details_attributes_0_email" class="form-control"> </div> <div class="clearfix"></div> <input type="hidden" value="false" name="event_venue[event_contact_details_attributes][0][_destroy]" id="event_venue_event_contact_details_attributes_0__destroy"><a onclick="remove_fields(this); return false;" href="#">remove</a> </div> </div>
event venue model,
has_many :event_contact_details, :dependent => :destroy accepts_nested_attributes_for :event_contact_details, allow_destroy: true
controller,
def new @event_venue = eventvenue.new @event_venue.event_contact_details.build end
form,
<%= f.fields_for :event_contact_details |builder| %> <%= render :partial => 'event_venues/event_contact_detail_fields', :locals => { :f => builder } %> <% end %> <p><%= link_to_add_fields "add more", f, :event_contact_details %></p>
Comments
Post a Comment