Rails - 无法将简单选择转换为选定字段

时间:2017-07-11 08:49:33

标签: ruby-on-rails

我有什么

我在视图上有一个简单的选择字段,它不是任何形式的一部分,选择任何选项都会向路径发送远程请求。

表中列出的视图中有许多应用程序,每个应用程序都有此下拉列表,用户可以使用该下拉列表为应用程序分配标记。此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'} %>

这就是视野中的字段

enter image description here

这就是我期待它看起来像

的方式

enter image description here

我还添加了javascript部分,但这也无济于事

$('.chzn-select').chosen();

问题

我在这里做错了什么:)

0 个答案:

没有答案