Appointment
モデルがあり、その各インスタンスにはClient
. 予定を編集するための私のテンプレートは次のとおりです。
<form id="edit-appointment" name="appointment" class="mobile_friendly">
<div class="field">
<input type="text" name="start_time_ymd" id="start_time_ymd" value="<%= start_time_ymd %>" placeholder="Start Date">
<input type="text" name="start_time_time" id="start_time_time" value="<%= start_time_time %>" placeholder="Start Time">
</div>
<div class="field">
<input type="text" name="client_name" id="client_name" value="<%= client.name %>" placeholder="Client">
<input type="hidden" name="client_id" id="client_id" value="<%= client.id %>" placeholder="Client ID">
</div>
<div class="field">
<input type="text" name="client_phone" id="client_phone" value="<%= client.phone %>" placeholder="Phone">
</div>
<div class="field">
<input type="text" name="notes" id="notes" value="<%= notes %>" placeholder="Notes">
</div>
<div class="actions">
<input type="submit" value="Update Appointment" />
</div>
</form>
<a href="#/index/<%= stylist_id %>">Back</a>
私の問題は、Client
属性がサーバーに正しく渡されていないことです。保存時にサーバーに渡される JSON オブジェクトは次のようになります。電話番号を持つクライアントがいるふりをしましょうが、555-555-5555
それを変更し555-555-1234
てフォームを送信します。
{"appointment":
{"start_time_ymd":"1/1/2000",
"client_phone":"555-555-1234",
"client":{"phone":"555-555-5555"}}
無関係なフィールドの多くを省略しましたが、私の言いたいことがわかると思います。client_phone
から555-555-5555
に変更しまし555-555-1234
たがclient
、JSON オブジェクト内のオブジェクトの電話番号は変更されていません。どうにかしてその電話番号を変更する必要があります。
電話番号フィールドのように、これらのフィールドを実際に「取る」ようにするにはどうすればよいclient
ですappointment
かappointment
? それが違いを生む場合、私はバックボーンリレーショナルを使用しています。