Ich habe eine Rails 4-Anwendung mit einigen Coffeescript, die meist verwendet wird, um Listen bei der Auswahl eines Elements in einer anderen Liste zu aktualisieren - ziemlich grundlegende Sachen.Rails 4 CoffeeScript nicht ausgeführt, wenn vorkompiliert
Das Skript funktioniert perfekt in der Entwicklung. Sobald es jedoch vorkompiliert wird, obwohl der tatsächliche Code in der vorkompilierten Asset-Datei angezeigt wird, wird er überhaupt nicht ausgeführt.
Ich habe den Code auf einen sehr minimalen Bereich reduziert, also wird nur eine Warnung angezeigt, wenn ein Kombinationsfeld geändert wird und immer noch nicht funktioniert. Ich habe auch alle .coffee-Dateien aus dem Verzeichnis "assets/javascript" entfernt, um nur diese eine Coffeescript-Datei und die Datei application.js zu behalten, um sicherzustellen, dass es keine Konflikte mit anderen .coffee-Dateien gibt.
Ich hatte auch Verdacht auf Turbolinks, die ich dann entfernt und immer noch nicht geändert habe.
application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require_tree .
attendance.coffee
$('#season_id').on "change", ->
alert('Success!')
Die Form von app/views/Anwesenheiten/_form.html.erb
<div class="container">
<form action="/attendances/get_attendance_sheet" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /> <table class="table">
<tr>
<td>Saison:</td>
<td><select name="season_id" id="season_id" class="form-control"><option value="">Choisir une saison</option><option value="1">Gadbois 2015</option></select></td>
<td>Entraînement du:</td>
<td><select name="session_id" id="session_id" class="form-control"><option value="">Choisir une date d'entraînement</option><option value=""></option></select></td>
<td><input type="submit" name="commit" value="Ouvrir" class="btn btn-success" /></td>
</tr>
</table>
</form></div>
Schlechte Turbolinks ... jeder nimmt an, dass es der Übeltäter ist. – coreyward
Könnten Sie '$ (document) .on 'change', '#season_id', -> alert 'Success'' versuchen? – Leito