次のように作成されたselectタグがあります。
<%= f.select(:id, category_options, include_blank:true) %>
フォームが正常に表示され、適切なモデルアイテムのオプションタグが選択されます。ただし、ユーザーが別のオプションを選択してフォームを送信すると、新しいオプションはサーバーに渡されません。代わりに、最初に選択された値がサーバーに渡されます。
Railsログには、新しい値ではなく、送信されている古い値が表示されます。この入力の値はキャッシュされているように見えます。これは開発と本番環境で発生し、開発ではcache_classes=falseです。
レールは次のようにログに記録されます。
2012-09-1113:42:51-0400に127.0.0.1のPUT"/posts / 1999"を開始しました。GalleriesController#updateによるHTMLとしての処理
パラメータ:{"utf8" => "✓"、 "authenticity_token" => "..."、 "gallery" => {"publish_on" => "2012-09-18"、 "poster_file_temp" => ""、 "thumb_file_temp" => ""、 "models_attributes" => {"0" => {"id" => "116"、 "_ destroy" => "false"}、 "1" => {"id" => "6409"、 "_ destroy" => "false"}}、 "categories_attributes" => {"0" => {"id" => "59"、 "_ destroy" => "false"}}、 "thumb_zip_input" => ""、 "medium_zip_input" => ""、 "large_zip_input" => ""、 "website_url" => ""、 "commit" => "Upload "、" id "=>" 1999 "}
フォームは次のようになります。
<form accept-charset="UTF-8" action="/galleries/1999" class="edit_gallery" enctype="multipart/form-data" id="edit_gallery_1999" method="post" name="edit_gallery_1999">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="...">
</div>
<div class="vert">
<label for="gallery_publish_on">Publish on</label> <input id="gallery_publish_on" name="gallery[publish_on]" size="30" type="text" value="2012-09-18"> <label for="gallery_poster_file">Poster file</label> <input id="gallery_poster_file_temp" name="gallery[poster_file_temp]" type="hidden"><input id="gallery_poster_file" name="gallery[poster_file]" size="30" type="file">
<div class='formSection'>
<img alt="Brandy" src="/content/gallery/poster_file/0000/1999/brandy.jpg">
</div><label for="gallery_thumb_file">Thumb file</label> <input id="gallery_thumb_file_temp" name="gallery[thumb_file_temp]" type="hidden"><input id="gallery_thumb_file" name="gallery[thumb_file]" size="30" type="file">
<div class='formSection'>
<img alt="Thumb" src="/content/gallery/thumb_file/0000/1999/thumb.jpg">
</div>
<div id="models">
<label for="Models">Models</label>
<div>
<select id="gallery_models_attributes_0_id" name="gallery[models_attributes][0][id]">
<option value="6409">
April
</option>
<option value="6366" selected="selected">
Brandy
</option>
<option value="9036">
Charlie
</option>
<option value="7490">
Craig
</option>
<option value="9881">
Donna
</option>
</select> <input id="gallery_models_attributes_0__destroy" name="gallery[models_attributes][0][_destroy]" type="hidden" value="false"> <a href="#" class="remove_fields">remove</a>
</div><input id="gallery_models_attributes_0_id" name="gallery[models_attributes][0][id]" type="hidden" value="6366"> <a href="#" class="add_fields" data-fields="<div> <select id="gallery_models_attributes_70106238269060_id" name="gallery[models_attributes][70106238269060][id]"><option value=""></option><option value="6409">April</option><option value="6366">Brandy</option><option value="9036">Charlie</option><option value="7490">Craig</option><option value="9881">Donna</option></select> <input id="gallery_models_attributes_70106238269060__destroy" name="gallery[models_attributes][70106238269060][_destroy]" type="hidden" value="false" /> <a href="#" class="remove_fields">remove</a></div>" data-id="70106238269060">add model</a>
</div>
<div id="categories">
<label for="Categories">Categories</label>
<div>
<select id="gallery_categories_attributes_0_id" name="gallery[categories_attributes][0][id]">
<option value="1">
Amateur
</option>
<option value="2">
Animals
</option>
<option value="49">
Articles
</option>
<option value="3">
Art
</option>
<option value="7">
Blog
</option>
</select> <input id="gallery_categories_attributes_0__destroy" name="gallery[categories_attributes][0][_destroy]" type="hidden" value="false"> <a href="#" class="remove_fields">remove</a>
</div><input id="gallery_categories_attributes_0_id" name="gallery[categories_attributes][0][id]" type="hidden" value="59"> <a href="#" class="add_fields" data-fields="<div> <select id="gallery_categories_attributes_70106278052860_id" name="gallery[categories_attributes][70106278052860][id]"><option value=""></option><option value="1">Amateur</option><option value="2">Animal</option><option value="49">Articles</option><option value="3">Art</option><option value="7">Blog</option></select> <input id="gallery_categories_attributes_70106278052860__destroy" name="gallery[categories_attributes][70106278052860][_destroy]" type="hidden" value="false" /> <a href="#" class="remove_fields">remove</a></div>" data-id="70106278052860">add category</a>
</div>
<div id='photoset_files'>
<fieldset>
<legend>Zip Files</legend> <label for="gallery_thumb_zip_input">thumb zip</label> <select id="gallery_thumb_zip_input" name="gallery[thumb_zip_input]">
<option value="/Library/WebServer/Documents/uploads/thumb copy.zip">
thumb copy.zip
</option>
<option value="/Library/WebServer/Documents/uploads/thumb.zip">
thumb.zip
</option>
</select> [ thumb.zip ]<br>
<label for="gallery_medium_zip_input">medium zip</label> <select id="gallery_medium_zip_input" name="gallery[medium_zip_input]">
<option value="/Library/WebServer/Documents/uploads/medium copy 10.zip">
medium copy 10.zip
</option>
<option value="/Library/WebServer/Documents/uploads/medium copy 9.zip">
medium copy 9.zip
</option>
<option value="/Library/WebServer/Documents/uploads/medium copy.zip">
medium copy.zip
</option>
<option value="/Library/WebServer/Documents/uploads/medium.zip">
medium.zip
</option>
</select> [ medium.zip ]<br>
<label for="gallery_large_zip_input">large zip</label> <select id="gallery_large_zip_input" name="gallery[large_zip_input]">
<option value="/Library/WebServer/Documents/uploads/large copy 10.zip">
large copy 10.zip
</option>
<option value="/Library/WebServer/Documents/uploads/large copy 9.zip">
large copy 9.zip
</option>
<option value="/Library/WebServer/Documents/uploads/large copy.zip">
large copy.zip
</option>
<option value="/Library/WebServer/Documents/uploads/large.zip">
large.zip
</option>
</select> [ large.zip ]<br>
</fieldset>
</div><label for="gallery_website_url">Website url</label> <input class="wider" id="gallery_website_url" name="gallery[website_url]" size="30" type="text" value=""> <input id="tluo" name="tluo" type="hidden" value="aHR0cDovL2tmLmRldi9nYWxsZXJpZXMvbGlzdA==">
<div id="submit">
<input data-disable-with="Uploading..." name="commit" type="submit" value="Upload"> <a href="/galleries/">Cancel</a>
</div>
</div>
</form>