I have a Rails app in which I use the gem chosen-rails (or chosen-sass-bootstrap-rails): In my gemfile I have this:
gem 'chosen-sass-bootstrap-rails'
It previously used to work, but now I constantly get this error - and I'm not sure why:
[Error] TypeError: undefined is not a function (evaluating '$('.chosen- select').chosen({
allow_single_deselect: true,
no_results_text: 'No results matched',
width: '100%'
})')
My application.js looks like this:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery.turbolinks
//= require chosen-jquery
//= require scaffold
//= require jquery.purr
//= require best_in_place
//= require bootstrap-datepicker
//= require jquery-fileupload
//= require autocomplete-rails
//= require jquery-ui
//= require jquery.countdown
//= require autocomplete-rails
//= require bootstrapValidator.min
//= require turbolinks
//= require_tree .
And in application.css.scss I have this line:
*= require chosen_bootstrap
My HTML (or (HAML) looks like this:
= select_tag "tag", options_from_collection_for_select(@team_tags, 'name', 'name', params[:tag]), prompt: "All tags", class: 'form-control chosen-select select-ideas-tag', onchange: "window.location.replace('/teams/#{@team.id}/tags/' + this.value + '?search=#{params[:search]}');"
And my JS (or CoffeeScript) looks like this:
# enable chosen js
$('.chosen-select').chosen
allow_single_deselect: true
no_results_text: 'No results matched'
width: '100%'
Any ideas why it isn't working?
Update
Seems like it's not only chosen-rails that have stopped working, but it seems like JS have stopped working altogether. None of my libraries works as expected. I have tried to both rebuild and cleaned my assets, but it didn't help.
Not sure what could have caused this, or how to find the main issue.
Any ideas?
It turned out that I wan including
jQuerytwice. Once inapplication.htmland also inapplication.js. Removing the one inapplication.htmlmade it work.