【问题标题】:Ruby on Rails -- ActionView::Template::Error (SyntaxError unexpected if) in CoffeeScriptRuby on Rails -- CoffeeScript 中的 ActionView::Template::Error (SyntaxError unexpected if)
【发布时间】:2018-02-10 22:11:39
【问题描述】:

我有以下.js.coffee 文件:

$('#search-results').html('<%= j render @articles %>');

$(document).ready () -> 
  dialog = document.querySelector('dialog');

  if (!dialog.showModal) {
    dialogPolyfill.registerDialog(dialog);
  }

  dialog.showModal();

  dialog.querySelector '.close', addEventListener 'click', () ->
    dialog.close();

为什么我会收到错误消息?

【问题讨论】:

    标签: javascript ruby-on-rails ruby coffeescript asset-pipeline


    【解决方案1】:

    在 CoffeeScript 中,您使用缩进而不是大括号。

    替换

    if (!dialog.showModal) {
      dialogPolyfill.registerDialog(dialog);
    }
    

    if (!dialog.showModal)
      dialogPolyfill.registerDialog(dialog)
    

    我建议通过documentation

    【讨论】:

    • 谢谢!并且原谅无知以前从未喝过咖啡。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 2018-03-26
    相关资源
    最近更新 更多