Javascript 未捕获的 ReferenceError:未定义日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32564028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 10:37:35  来源:igfitidea点击:

Uncaught ReferenceError: date is not defined

javascriptruby-on-rails

提问by Sebastian Jennings Almnes

Hey I'm trying to create a heartbeat that will tell me when a customer is done with a session.

嘿,我正在尝试创建一个心跳,当客户完成会话时,它会告诉我。

My controller looks like this:

我的控制器看起来像这样:

def update
  @customer = Customer.find(params[:id])
  @room = Room.find(params[:room_id])
  @customer.charge(@room)
  @customer.update_attribute(finished_at: DateTime.now)
  session[:customer_id] = nil

  respond_to do |format|
    format.js
    format.htmt { redirect_to root_url }
  end
end

now in my show.html.erb file I have this:

现在在我的 show.html.erb 文件中我有这个:

setInterval(function(){
  $.post("/customers/<%= current_customer.id %>", {finished_at: date.now()}, function(){});
}, 5000);

now when I check my console the error I get is:

现在当我检查我的控制台时,我得到的错误是:

Uncaught ReferenceError: date is not defined

There might be a couple of mistakes here, anybody knows whats up?

这里可能有几个错误,有人知道怎么回事吗?

回答by Tushar

dateis not the valid syntax.

date不是有效的语法。

Use Datenot date, note the uppercase D

使用Datenot date,注意大写D

Date.now()

Docs

文档