如何在nested_form_for rails中编辑字符串数组字段?

时间:2016-01-19 13:38:32

标签: javascript jquery html ruby-on-rails

fields_for中的第一行,使用" 0" index:

<tr class="ui-state-disabled" id="bold_col">    
    <td class="col-sm-2 drag-enable">      
        <input class="form-control diminished-font educations education col1"
               name="resume[educations_attributes][0][ecolumns][]" value="Institution"
               placeholder="Institution" type="text" id="1">
    </td>
    <td class="col-sm-2 drag-enable">
        <input class="form-control diminished-font educations education col2"
               name="resume[educations_attributes][0][ecolumns][]" value="City"
               placeholder="City" type="text" id="2">
    </td>
</tr>

fields_for中的第二行,使用&#34; 1&#34;指数:

<tr class="fields">
    <td class="col-sm-2 drag-enable">
        <%= text_field_tag 'resume[educations_attributes][1][ecolumns][]',"",:class=>"form-control diminished-font col1 educations educations",:placeholder=>"" %>
    </td>
    <td class="col-sm-2 drag-enable" >
        <%= text_field_tag 'resume[educations_attributes][1][ecolumns][]',"",:class=>"form-control diminished-font col2 educations educations",:placeholder=>"" %>
    </td>
</tr>

我可以通过&#34; link_to_add&#34;在表格中添加任意数量的行功能。在创建时它工作正常,但在编辑时,我遇到了问题,因为手动创建了所有这些字段的名称。我怎么能在这里使用rails东西?有什么好方法吗?

0 个答案:

没有答案