错误:第28行上的解析错误:意外的'终止'

时间:2013-12-17 20:29:34

标签: ruby-on-rails coffeescript stripe-payments

新的咖啡脚本,我不知道是什么导致了这个。

$ ->
    $('.subscription').hover (event) ->
        $(this).toggleClass("hover")


jQuery ->
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
  payment.setupForm()

payment =
  setupForm: ->
    $('#new_subscription').submit ->
      $('input[type=submit]').attr('disabled', true)
      payment.processCard()
      false

  processCard: ->
    card =
      number: $('#card_number').val()
      cvc: $('#card_code').val()
      expMonth: $('#card_month').val()
      expYear: $('#card_year').val()
      Stripe.createToken(card, payment.handleStripeResponse)

  handleStripeResponse: (status, response) ->
    if status == 200
      alert(response.id)
    else
      alert(response.error.message)

2 个答案:

答案 0 :(得分:1)

错误是由此行引起的:Stripe.createToken card, payment.handleStripeResponse。它不是card对象的一部分。

我把这一切都变得更加咖啡了:

$ ->
  $('.subscription').hover (event) ->
    $(this).toggleClass "hover"

jQuery ->
  Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
  payment.setupForm()

payment =
  setupForm: ->
    $('#new_subscription').submit ->
      $('input[type=submit]').attr 'disabled', no
      payment.processCard()
      false

  processCard: ->
    card =
      number: $('#card_number').val()
      cvc: $('#card_code').val()
      expMonth: $('#card_month').val()
      expYear: $('#card_year').val()
    Stripe.createToken card, payment.handleStripeResponse

  handleStripeResponse: (status, response) ->
    if status is 200
      alert response.id 
    else
      alert response.error.message

答案 1 :(得分:1)

processCard: ->
    card =
      number: $('#card_number').val()
      cvc: $('#card_code').val()
      expMonth: $('#card_month').val()
      expYear: $('#card_year').val()
    Stripe.createToken(card, payment.handleStripeResponse)  # <-- wrong identation