Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: date is not defined

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:

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?

like image 349
Sebastian Jennings Almnes Avatar asked Sep 14 '15 11:09

Sebastian Jennings Almnes


1 Answers

date is not the valid syntax.

Use Date not date, note the uppercase D

Date.now()

Docs

like image 66
Tushar Avatar answered Oct 13 '22 11:10

Tushar