我有一个这样构建的选择标签:
<%= f.select(:id, category_options, include_blank:true) %>
表单显示正常,并选择了适当的模型项的选项标签。但是,当用户选择不同的选项并提交表单时,新选项不会传递给服务器。相反,最初选择的值被传递给服务器。
rails 日志显示正在提交的旧值,而不是新值。此输入的值似乎已缓存。这发生在开发和生产中,并且在开发中 cache_classes = false。
rails 日志如下:
在 2012-09-11 13: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"=>"上传", "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>