Rails4、Turboxlinks和select2:Object[Object Object]没有方法'选择2

Rails4, Turbolinks, and select2: Object [object Object] has no method 'select2'

本文关键字:Object 有方法 选择 Turboxlinks select2 Rails4      更新时间:2023-09-26

有人能帮我吗?我收到错误:

Object [object Object] has no method 'select2'

如果我正在使用涡轮链接进行链接。但如果我重新加载页面,select2就可以了。

application.js

//= require jquery
//= require jquery_ujs
//= require select2
//= require foundation
//= require turbolinks
//= require_tree .
$(function(){ $(document).foundation(); });

events.js.coffee

loadAdress = (json) ->
    $("#event_adress").val json.adress + "'n" + (if json.zipcode? then json.zipcode else '') + ' ' + json.town
    $("#event_name").val json.name
    $("#event_cell_phone").val (if json.cellPhone? then '+45'+json.cellPhone else '') 
    $(".hidden").slideDown()
ready = ->
    if $("#event_contact_id").length > 0
        $("#event_contact_id").select2
            width: "element"
            placeholder: "Find kunde"
        $("#event_contact_id").on "select2-selecting", (e) ->
            $.ajax "/contacts/" + e.val + ".json",
            dataType: "json"
            success: loadAdress
$(document).ready(ready)
$(document).on('page:load', ready)

我希望有人能帮我解决这个问题,因为我已经试着解决这个问题好几个小时了。

$(document).on 'ready page:load', ->
  #your stuff

我决定不使用涡轮链接并将其删除。

相关文章: