我有什么
我在视图上有一个简单的选择字段,它不是任何形式的一部分,选择任何选项都会向路径发送远程请求。
表中列出的视图中有许多应用程序,每个应用程序都有此下拉列表,用户可以使用该下拉列表为应用程序分配标记。此select_tag
的代码如下。
<%= select_tag 'application_tag',
options_from_collection_for_select(HiringTag.order(:name), :id, :name, application.tag),
prompt: "Assign a tag to the application",
class: "form-control input-block-level chzn-select",
id: "hiring_tag_dropdown",
data: {
remote: true,
url: "applications/"+application.id.to_s+"/assign_tags",
method: 'post'
}
%>
现在,它可以正常工作,并且正在为应用程序分配标记。
我想做什么
我正在尝试使用select_tag
将此collection_select
转换为多选字段,而我使用的gem是gem 'chosen-rails'
。看一下文档和其他一些博客文章,这似乎是一项直接的工作,但我不能让这个领域看起来应该如此。这就是我所做的。
<%= collection_select :application_id, :application_tag, HiringTag.order(:name), :id, :name, {}, {include_blank: true, multiple: true, class: 'form-control input-block-level chzn-select'} %>
这就是视野中的字段
这就是我期待它看起来像
的方式我还添加了javascript部分,但这也无济于事
$('.chzn-select').chosen();
问题
我在这里做错了什么:)