select2-rails gem is not working on Rails4

前端 未结 4 575
一个人的身影
一个人的身影 2021-01-02 17:55

I have tried given documentation for the select2-rails gem, but my browser console still throws an error.

Uncaught TypeError: $(...).select2 is not a

4条回答
  •  鱼传尺愫
    2021-01-02 18:39

    The problem is surely in application.js: According to their Demo App, the sequence of requiring JS plugins is as follows:

    //= require jquery
    //= require jquery_ujs
    //= require turbolinks
    //= require select2
    //= require select2_locale_pt-BR
    //= require_tree .
    

    In your case, you have to load turbolinks before select2, leading to:

    //= require jquery
    //= require turbolinks
    //= require select2
    //= require jquery.ui.accordion
    //= require jquery.ui.menu
    //= require jquery.ui.datepicker
    //= require common
    //= require posts
    //= require twitter/bootstrap
    //= require owl.carousel
    //= require vendor_js
    //= require_tree .
    

提交回复
热议问题