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?
date
is not the valid syntax.
Use Date
not date
, note the uppercase D
Date.now()
Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With