selected-rails gem不起作用

key*_*ons 5 css jquery ruby-on-rails jquery-chosen

我已经阅读了许多其他相关问题,但是无法让这个宝石工作:

https://github.com/tsechingho/chosen-rails

正如README所说,我有

-included *= require chosen in my application.css

-included //= require chosen-jquery in my application.js 
Run Code Online (Sandbox Code Playgroud)

另外,我尝试将followin添加到我的application.js文件底部:

jQuery(function($){
    $('.chzn-select').chosen();
});
Run Code Online (Sandbox Code Playgroud)

我也换成.chzn-select#user_education_ids#user_school_ids基于我的模型和视图:

<% @schools = Education.all.map { |e| [ e.school, e.school ] } %>
              <%= select_tag "school_ids", options_for_select((@schools), params[:education_id]), { :include_blank => true, :multiple => true } %>
Run Code Online (Sandbox Code Playgroud)

我试过添加, :class=>'chzn-select'到最后:multiple => true,没有运气

(用户有很多教育,以及许多学校通过教育)

不知道为什么这给了我这么多麻烦,但确实如此.非常感谢帮助!

小智 1

我知道这有点晚了,但我也遇到了让它工作的问题。

我通过将“gem 'chosen-rails'”行移动到 Gemfile 中的 :assets 块之外来使其工作(我注意到您对相关 Railscast 的评论,Ryan 将其放在 :assets 块中,所以我假设你也这么做了)。

我不确定这是否是“正确”的解决方案,或者可能有什么副作用,但它现在似乎有效。