0

我希望能够将令牌字段(在此处找到:http : //railscasts.com/episodes/258-token-fields)与 formtastic 一起使用以允许用户输入标签(我正在使用acts_as_taggable_on)。

有人可以告诉我如何做到这一点的例子吗?

4

1 回答 1

1

我没有时间进行完整的演练,但这似乎是 atext_field有一个data-pre带有一些 JSON 的属性。在 Formtastic 中向输入添加属性的方法是通过 :input_html 选项,所以:

<p>
  <%= f.label :author_tokens, "Authors" %><br />
  <%= f.text_field :author_tokens, "data-pre" => @book.authors.map(&:attributes).to_json %>
</p>

可能被翻译成类似的东西:

<%= f.input :author_tokens, :input_html => { "data-pre" => @book.authors.map(&:attributes).to_json } %>

剩下的就是将 CSS 粘贴到 HTML 上并找到正确的 DOM 元素来应用 jQuery(查看源代码是你的朋友)。

于 2011-05-25T00:33:25.330 回答