0

ネストされたモデル フォームについては、Ryan Bate の RailsCast ( #197 ) をフォローしています。

コントローラーに 3 つのフィールドが追加されたフォームを送信すると、次のようになります。

3.times { @prof.experiences.build }

...きちんと保存されます。ただし、フィールドが jQuery 経由で追加された場合、保存されません。

他の誰かが以前にこの種の問題を経験したことがありますか?

編集:jQueryなしで生成されたHTML:

<div class="fields">
<table>
<tbody><tr>
<td>Position Title:</td>
<td><input id="applicant_profile_experiences_attributes_0_title" name="applicant_profile[experiences_attributes][0][title]" size="30" type="text"></td>
</tr>
<tr>
<td>Employer:</td>
<td><input id="applicant_profile_experiences_attributes_0_employer" name="applicant_profile[experiences_attributes][0][employer]" size="30" type="text"></td>
</tr>
<tr>
<td>Responsibilities</td>
<td><textarea cols="40" id="applicant_profile_experiences_attributes_0_description" name="applicant_profile[experiences_attributes][0][description]" rows="4"></textarea></td>
</tr>
<tr>
<td>Start Date:</td>
<td><select id="experience_from_date_1i" name="experience[from_date(1i)]">
<option value="1970">1970</option>
<option value="1971">1971</option>
</select>
</td>
</tr>

</tbody></table>
<p><input id="applicant_profile_experiences_attributes_0__destroy" name="applicant_profile[experiences_attributes][0][_destroy]" type="hidden" value="false"><a href="#" onclick="remove_fields(this); return false;">Remove</a></p>
</div>

jQuery で追加されたコード:

<div class="fields">
<table>
    <tbody><tr>
        <td>Position Title:</td>
        <td><input id="applicant_profile_experiences_attributes_1366407307283_title" name="applicant_profile[experiences_attributes][1366407307283][title]" size="30" type="text"></td>
    </tr>
    <tr>
        <td>Employer:</td>
        <td><input id="applicant_profile_experiences_attributes_1366407307283_employer" name="applicant_profile[experiences_attributes][1366407307283][employer]" size="30" type="text"></td>
    </tr>
    <tr>
        <td>Responsibilities</td>
        <td><textarea cols="40" id="applicant_profile_experiences_attributes_1366407307283_description" name="applicant_profile[experiences_attributes][1366407307283][description]" rows="4"></textarea></td>
    </tr>
    <tr>
        <td>Start Date:</td>
        <td><select id="experience_from_date_1i" name="experience[from_date(1i)]">
<option value="1970">1970</option>
<option value="1971">1971</option>
<!-- removed big date list -->
</select>
</td>
    </tr>

</tbody></table>
<p><input id="applicant_profile_experiences_attributes_1366407307283__destroy" name="applicant_profile[experiences_attributes][1366407307283][_destroy]" type="hidden" value="false"><a href="#" onclick="remove_fields(this); return false;">Remove</a></p>
</div>
4

0 に答える 0