Rails:未调用Coffeescript点击处理程序

时间:2015-09-17 17:09:55

标签: jquery ruby-on-rails coffeescript onclick asset-pipeline

一个coffeescript点击处理程序我绑定到我的rails应用程序中的播放按钮是不被调用的,并且onsubmit处理程序也不是(因此initialiseTimer()下的两个听众都不是被称为。)

我在console.log("MESSAGE")之前和之后运行initialiseTimer() - 两次打印到控制台。但是onsubmit和onclick处理程序的情况并非如此。

这有什么明显的原因?我是coffeescript的新手。谢谢!

timestamps.coffee

initialiseTimer = ->
    $('#counter').timer format: '%H:%M:%S'
    $('#counter').timer "pause"
    timerPaused = true 

resetTimerDisplay = ->
    $('#counter').timer "reset"

playOrPause = ->
    if timerPaused is true
        $('#counter').timer "resume"
        timerPaused = false
    else 
        $('#counter').timer "pause"
        timerPaused = true

$(document).ready ->
    initialiseTimer()

    $('#playback_buttons').click ->
      playOrPause()

    $('#new_timestamp').submit ->
        $('#counter').timer "pause"
        if $('#timestamp_seconds_elapsed').trim().val().length > 0
            seconds = $('#counter').data('seconds')
            $('#timestamp_seconds_elapsed').val(seconds)
            $('#counter').timer "reset"
            $('#counter').timer "pause"
        else
            $('#counter').timer "reset"
            $('#counter').timer "pause"

new.html.erb

<div class="new_timestamp_form">
  <div class="form_content">
    <h1>New Timestamp</h1>

    <%= render 'new_form' %>

    <%= link_to 'Back', @project %>
  </div>
</div>

_new_form.html.erb

<div id="timer_wrapper">
  <div id="counter"></div>
  <div id="playback_buttons">&#9658;</div>
</div>

<%= form_for [@project, @timestamp] do |f| %>
  <% if @timestamp.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@timestamp.errors.count, "error") %> prohibited this timestamp from being saved:</h2>

      <ul>
      <% @timestamp.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :seconds_elapsed %><br>
    <%= f.number_field :seconds_elapsed %>
  </div>
  <div class="actions">
    <%= f.submit'New Timestamp', :class => 'button' %>
  </div>
<% end %>

0 个答案:

没有答案