select2-rails gem seems to have problems with the browser-back function in my project:
Steps to recreate bug:
- go to http://methoden-app.herokuapp.com/
- click on any link
- use back button of your browser
the select2-selects in the form will have doubled: image of bug
my code:
Gemfile:
ruby 2.3.1
rails 5.0.0.1
gem select2-rails 4.0.3
view:
<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 %>
controller:
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
What I tried:
- chrome-pc, chrome-android and firefox-pc -> no difference
- put select2 jquery-code in application.js/practices.coffee -> form is not using select2-styling
removing following snippet, but leaving the part between "{}" -> form not using select2-styling
$(document).ready(function() { ... });
add
autocomplete: 'off'
-> no difference- searching the web for 2 days
- trying to write a test for the bug, put giving up due to lack of knowledge
My questions:
- Any ideas on why this happens and what to do about it?
How can i use the browser-back function in my test for the bug? (I only know Minitest, no 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
I'm still pretty new to programming (coming straight from Michael Hartls rails tutorial into this project). So I hope you pros can help me ;) THX