【发布时间】:2014-07-04 14:18:28
【问题描述】:
我正在使用 ActsAsTaggableOn gem 并想从标签列表中选择多个标签。所以我尝试使用下拉菜单选择多个标签。代码如下:
= form_for(@post) do |f|
- if @post.errors.any?
#error_explanation
%h2
= pluralize(@post.errors.count, "error")
prohibited this post from being saved:
%ul
- @post.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :title
%br/
= f.text_field :title
.field
= f.label :body
%br/
= f.cktext_area :body, :class => 'ckeditor'
.field
= f.label :tag_list
%br/
= f.collection_select :tag_list, ActsAsTaggableOn::Tag.all, :id, :name, :prompt => "--- Select Tags ---", {:multiple => true}
.actions
= f.submit
但不知何故,我只能选择单个标签而不是多个标签。所以我现在使用复选框来选择多个标签。修改后的代码行如下:
= f.collection_check_boxes :tag_list, ActsAsTaggableOn::Tag.all, :id, :name
现在输出看起来像,
Tag list
[#", label="Check">, #", label="Invitation">, #", label="Payment">, #", label="Complain">, #", label="Maintenance">, #", label="Meeting">]
我不确定是什么问题。我是 ruby 新手,它可能有一个简单的解决方案来解决我无法弄清楚的问题。请帮助我,因为我已经用 Google 搜索了一天并尝试了所有更改,但仍然遇到此问题。
编辑
当raw 被移除时,它呈现为:
Tag list
[#<struct MetaSearch::Check box="<input id=\"post_tag_list_1\" name=\"post[tag_list][]\" type=\"checkbox\" value=\"1\" />", label="<label for=\"post_tag_list_1\">Check</label>">, #<struct MetaSearch::Check box="<input id=\"post_tag_list_2\" name=\"post[tag_list][]\" type=\"checkbox\" value=\"2\" />", label="<label for=\"post_tag_list_2\">Invitation</label>">, #<struct MetaSearch::Check box="<input id=\"post_tag_list_3\" name=\"post[tag_list][]\" type=\"checkbox\" value=\"3\" />", label="<label for=\"post_tag_list_3\">Payment</label>">, #<struct MetaSearch::Check box="<input id=\"post_tag_list_4\" name=\"post[tag_list][]\" type=\"checkbox\" value=\"4\" />", label="<label for=\"post_tag_list_4\">Complain</label>">, #<struct MetaSearch::Check box="<input id=\"post_tag_list_5\" name=\"post[tag_list][]\" type=\"checkbox\" value=\"5\" />", label="<label for=\"post_tag_list_5\">Maintenance</label>">, #<struct MetaSearch::Check box="<input id=\"post_tag_list_6\" name=\"post[tag_list][]\" type=\"checkbox\" value=\"6\" />", label="<label for=\"post_tag_list_6\">Meeting</label>">]
【问题讨论】:
-
不要在上面使用
raw。
标签: ruby-on-rails ruby checkbox acts-as-taggable-on