こんにちは、このチュートリアルに従っていますが、モデルの編集中にフィールドの事前入力が機能しません..
編集中、text_field category_tokens にはカテゴリが事前入力されないことに注意してください。
以下はコード スニペットです。text_field の HTML 出力に値が表示されます。
<input id="product_category_tokens" type="text" size="30" name="product[category_tokens]" data-pre="[{"created_at":"2010-09-13T03:33:17Z","description":"","id":x,"name":"Kitchen & Dining ","parent_id":xx,"permalink":"kitchen-dining","updated_at":"2011-01-05T11:17:10Z"}]" style="display: none;">
application.js
$(function() {
$("#product_category_tokens").tokenInput("/categories.json", {
crossDomain: false,
prePopulate: $('#product_category_tokens').data('pre'),
preventDuplicates: true
});
});
<%= f.text_field :category_tokens, "data-pre" => @product.categories.map(&:attributes).to_json %>