I decided not to use turbolinks and removed it.
Rails4, Turbolinks, and select2: Object [object Object] has no method 'select2'
-
02-06-2022 - |
سؤال
Can someone help me with this, I get the error:
Object [object Object] has no method 'select2'
If i'm go through a link using turbolinks. But if I reload the page select2 works.
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)
I hope someone can help me out with this, because I have tried to solve this for hours now.
المحلول 2
نصائح أخرى
$(document).on 'ready page:load', ->
#your stuff
لا تنتمي إلى StackOverflow