浏览器后面的select2-rails行为不正常(显示两次)

时间:2016-11-28 10:10:23

标签: ruby-on-rails select2-rails

select2-rails gem似乎在我的项目中出现浏览器返回功能问题:

重建错误的步骤:

表单中的select2-choices将加倍:image of bug

我的代码:

的Gemfile:

ruby 2.3.1  
rails 5.0.0.1  
gem select2-rails 4.0.3

查看:

<head>
  <script>
    $(document).ready(function() {
      $(".multi_select").select2({ theme: bootstrap", placeholder: "Bitte mindestens 1 auswählen"
      });
    });
  </script>
</head>

<%=form_tag( practices_path, method: "get", remote: true ) do %>
  <div class="form-group">
    <%=label_tag(:category_ids, "Kategorien:") %>
      <%=select_tag( 'category_ids', options_from_collection_for_select(@categories, "id", "name"), class: "multi_select", multiple: true, style: "width: 100%", autocomplete: 'off' ) %>
  </div>
      .
      .
      .
  <div class="form-group">
    <%= label_tag(:area_ids, "Räume:") %>
    <%= select_tag( 'area_ids', 
        options_from_collection_for_select(@areas, "id", "name"), 
        class: "multi_select", multiple: true, style: "width: 100%" ) %>
  </div>
  <div class="form-group row">
    <%=submit_tag( "Filter anwenden", class: "btn btn-primary" ) %>
      <%=link_to "Filter zurücksetzen", root_path, class: "btn btn-default", style: "float: right" %>
  </div>
  <% end %>

控制器:

class PracticesController < ApplicationController  
  .
  .                                             
  .
  def index
    @categories = Category.all
    @areas = Area.all
    @practices = Practice.with_category(params[:category_ids])\
                         .with_participants(params[:participants])\
                         .with_min_duration(params[:min_duration])\
                         .with_max_duration(params[:max_duration])\
                         .with_age(params[:age])\
                         .with_areas(params[:area_ids])\
                         .paginate(:page => params[:page])
    respond_to do |format|
      format.html
      format.js
    end
  end
  .
  .
  .
end

我尝试了什么:

  • chrome-pc,chrome-android和firefox-pc - &gt;没有区别
  • 将select2 jquery-code放入application.js / practices.coffee中 - &gt;表单不使用select2-styling
  • 删除以下代码段,但将该部分留在“{}” - &gt;之间形式不使用select2-styling

    $(document).ready(function() { ... });
    
  • 添加autocomplete: 'off' - &gt;没有区别

  • 在网上搜索2天
  • 试图为错误编写测试,由于缺乏知识而放弃

我的问题:

  1. 关于为什么会发生这种情况以及该怎么做的任何想法?
  2. 如何在我的测试中使用浏览器返回功能来查找错误? (我只知道Minitest,没有Rspec)

    require 'test_helper'
    
    class PracticesIndexTest < ActionDispatch::IntegrationTest
    
    
      test "select2 should work properly" do
        get practices_path
        assert_template 'practices/index'
        assert_select 'select.multi_select', count: 2
        get practice_path(id: 2)
      # something like 'javascript:history.back()' ?
        assert_select 'select.multi_select', count: 2
      end
    end
    
  3. 我对编程还很陌生(直接从Michael Hartls rails教程进入这个项目)。所以我希望你的专业人士可以帮助我;)THX

0 个答案:

没有答案