lundi 25 mai 2015

How to submit multiple fields into an Array of values

Ok i have the following form fields that i would like to submit in an array of vehicle like

car = [{:year => 2012, :make => "Ford", :model => mustang}, {:year => 2015, :make => "Chevy", :model => "S-10"}, {:year => 2014, :make => "Dodge", :model => "Caravan"}]

at the moment it is sending in this (only the last set of car)

Parameters: {"utf8"=>"✓", "authenticity_token"=>"iMyNj94iSBuV3ZL0EVHRjet6kt4EEYe6Ajc1XA2Cq+8=", "post"=>{"title"=>"", "category_id"=>"1", "notes"=>"", "stops"=>"", "promote"=>"0", "user_id"=>"1"}, "car"=>{"year"=>"2016", "make"=>"", "model"=>""}, "commit"=>"Create Post"}

this is the form coding that i have

<div id="auto">
            <section style="margin-bottom: 0;">
  <div class="row">
    <div class="col col-md-4">
      <label class="select">
        <select class="pointer" id="car_year" name="car[year]"><option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
      </label>
    </div>
    <div class="col col-md-4">
      <label class="input">
        <input id="car_make" name="car[make]" placeholder="Make" type="text" value="">
      </label>
    </div>
    <div class="col col-md-4">
      <label class="input">
        <input id="car_model" name="car[model]" placeholder="Model" type="text" value="">
      </label>
    </div>
  </div>
</section>
          <section style="margin-bottom: 0;">
  <div class="row">
    <div class="col col-md-4">
      <label class="select">
        <select class="pointer" id="car_year" name="car[year]"><option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
      </label>
    </div>
    <div class="col col-md-4">
      <label class="input">
        <input id="car_make" name="car[make]" placeholder="Make" type="text" value="">
      </label>
    </div>
    <div class="col col-md-4">
      <label class="input">
        <input id="car_model" name="car[model]" placeholder="Model" type="text" value="">
      </label>
    </div>
  </div>
</section><section style="margin-bottom: 0;">
  <div class="row">
    <div class="col col-md-4">
      <label class="select">
        <select class="pointer" id="car_year" name="car[year]"><option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
</select>
      </label>
    </div>
    <div class="col col-md-4">
      <label class="input">
        <input id="car_make" name="car[make]" placeholder="Make" type="text" value="">
      </label>
    </div>
    <div class="col col-md-4">
      <label class="input">
        <input id="car_model" name="car[model]" placeholder="Model" type="text" value="">
      </label>
    </div>
  </div>
</section></div>

here is my form that i add more of these fields to dynamically...

enter image description here

Aucun commentaire:

Enregistrer un commentaire