1

I seem to be experiencing some sort of perennial problem regarding JS and Heroku. Although not exactly---some of my JS works, but not all.

I have the following in application.js:

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .


 function submitForm(pagenamed, starttime, endtime) {
      alert("checked the button - worked");
      $.ajax({
           type:'POST', 
           url: '/pagetimes/create', 
           data: $.param({ pagetime: {pagename: pagenamed, start: starttime, end: endtime }}),
           async:false
      });
 }

var d = new Date();
var starttime = d.getTime();
var pagename = document.URL
alert("load works START:" +d+ starttime + pagename);

window.onbeforeunload=function() {
var j = new Date();
var endtime = j.getTime();
alert("unload works START:" +d+ starttime +"END:"+j+ endtime +pagename );
      $.ajax({
           type:'POST', 
           url: '/pagetimes/create', 
           data: $.param({ pagetime: {pagename: pagename, start: starttime, end: endtime }}),
           async:false
      });
}

Which, as you may guess, is a JS to capture time spent on a page and record it under a model (pagetimes) via sending an AJAX call to the create action (all without user input). I am still developing so I have left a bunch of alerts in to show me when the functions get fired. There is also a function which I can call using a button which effectively does the same thing (how I debugged the AJAX call when I built it). All of this works seamlessly in localhost (development), but only the button works in production on Heroku. And even given that, both the onload and onbeforeunload actions fire on Heroku when expected (I get the alerts, exact same as in development), but nothing shows up in my database. Any thoughts on whats going wrong here?

There are a lot of answers out there about precompiling assets and then pushing to Heroku, or adjusting various options in the production.rb or application.rb file, have tried a bunch of those to no avail. Also some answers report ordering of the //=... lines in the application.js file matters (having something to do with bootstrap), I've tried that too but again nothing.

It must have something to do with the variables I am declaring in the event functions, or the async:none option? Otherwise I'm out of ideas. Am using the same browser for both localhost and heroku app. Is there anything obvious I might be missing? Using Rails 3, Win7, no fancy gems.

Update 1:

I found the following: JavaScript not loading on Heroku but works locally which sounds very similar to my problem. Could this be it?

Update 2:

I included the pagename variable in my alert to see if that wasn't working properly. Not the problem, the correct info appears in the alert. Also made the button and onbeforeunload async options the same in case that was it. Is not. Now everything about these ajax calls is the exact same, but one works and the other doesn't. What gives?

Community
  • 1
  • 1
SOConnell
  • 793
  • 1
  • 8
  • 27
  • I am using them there just to show me in the alert that they have been passed properly into the `onbeforeunload` event; they are declared outside the `onload` event so that they will be accessible there (otherwise they are not). basically this is just a remnant from debugging so I could ensure things are being passed properly. – SOConnell Jan 03 '14 at 05:40
  • I have updated my code to the above, and I still have the same issue: works perfectly on localhost (actions fire & data posted to db), actions fire in Heroku but nothing gets posted to my database. – SOConnell Jan 03 '14 at 05:47
  • Have you precompiled your assets? – Richard Peck Jan 03 '14 at 09:29
  • Yes, precompiling doesn't do anything for me... – SOConnell Jan 03 '14 at 14:49

1 Answers1

0

Here is the answer (for me)--nothing to do with JS, only the postgres DB. My integers were too big.

Integer out of range on Postgres DB

Heroku / Postgres Error: integer out of range

Community
  • 1
  • 1
SOConnell
  • 793
  • 1
  • 8
  • 27