【问题标题】:Using Chosen Plugin with Rails Select将所选插件与 Rails Select 一起使用
【发布时间】:2012-09-19 15:54:17
【问题描述】:

我正在尝试使用 chosen gem 为 rails 实现自动完成功能。这是一个 javascript 插件 Harvest here

我正在使用 rails 3.2.8 和 Simple Form 2.0.2 我正在尝试以使用 simpleform gem 的形式实现它。简单来说,我使用关联方法来选择用户可以/可能属于的所有机构(数据库中的另一个表)。

我一直在尝试将 2 个 railscasts 剧集 #102#258 组合在一起

我已将 gem 安装到我的 gem 文件中

gem 'chosen-rails'

我已经把需要的项目放在 application.js 中

//= require chosen-jquery

&application.css

 *= require chosen

我已在 users.js.coffee 文件中调用

jQuery ->
  $('#user_bankinst_name').chosen();

这是我尝试在其上使用插件的表单。这是“f.association”行。

            <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
              <%= f.error_notification %>
                <%= f.input :email, :required => true, :autofocus => true, :label => 'Username ( Your Email )', :placeholder => 'Email Address' %>
                <%= f.input :password, :required => true, :autofocus => true, :label => 'Password', :placeholder => 'Password' %>
                <%= f.input :password_confirmation, :required => true, :autofocus => true, :label => 'Confirm Password', :placeholder => 'Password Confirmation' %>
                <%= f.association :bankinst, :collection => Bankinst.order(:FinancialInstitutionName), :required => true, :autofocus => true, :label => 'Pick an Institution', :label_method=>:FinancialInstitutionName, :id => 'user_bankinst_name'  %>
                <%= f.button :submit, "Sign Up  >>", class: 'btn btn-inverse' %>
            <% end %>

我做错了什么?感谢您的帮助。

【问题讨论】:

    标签: jquery ruby-on-rails-3 jquery-chosen


    【解决方案1】:

    我想通了。

    我的班级缺少“:input_html”。

    我将咖啡文件更改为:

    jQuery ->
      $('.chzn-select').chosen()
    

    我把课程改成 chzn-select

    <%= f.association :bankinst, :collection => Bankinst.order(:FinancialInstitutionName), :required => true, :autofocus => true, :label => 'Pick an Institution', :label_method=>:FinancialInstitutionName, :input_html => {:class => "chzn-select" }  %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2015-11-16
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多