0

I have a list of 'destinations'. There is a LIKE button next to each destination as well as a like count. I was able to get this 'liking system' working locally. however, once deployed to heroku, the 'like count' is displayed as 'undefined' and then whenever you click the like button, the like count turns to 'NaN'. How can I get the liking system to work on my heroku app??

In my javscript console, I notice there is no like_count column like there should be. But my migration and schema file say otherwise...

Schmea.rb file:

create_table "destinations", force: :cascade do |t|
t.string   "name"
t.string   "address"
t.time     "start_time"
t.date     "date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer  "trip_id"
t.integer  "day_id"
t.integer  "like_count"
t.integer  "duration"
t.time     "end_time"

end

I implemented the liking system in a javscript file:

var like_cell = row.insertCell(2);
like_cell.innerHTML = '<input type="button" id="like-btn" type="button" value = "Like"</input>';
var like_count_cell = row.insertCell(3);
like_count_cell.innerHTML = dest.like_count; 

$('#like-btn').click(function() {
    dest.like_count += 1;
    like_count_cell.innerHTML=dest.like_count;
    console.log('hi');
    console.log(dest.like_count);
    console.log(dest);
    sortTable();
  });

  function sortTable(){
    var tbl = document.getElementById("destTable").tBodies[0];
    var store = [];
    for(var i=1, len=tbl.rows.length; i<len; i++){
      var row = tbl.rows[i];
      store.push([table.rows[i].cells[3].innerHTML, row]);
    }
      store.sort(function(x,y){
      return y[0] - x[0];
    });
    for(var j=0, len=store.length; i<len; i++){
      tbl.appendChild(store[j][1]);
    }
    table = tbl;
    store = null;
    }
coderk
  • 71
  • 12

1 Answers1

0

possibility to fell such things 1. Is JS files loading and without error? 2. Is ajax making call to correct url. (chances are there it is making calls to localhost as you said it is working on local) 3. Is ajax request takes long time? (heroku timeouts in 30 seconds) 4. Any cross browser problem is there? It is like trying to load contents from other site and from non secure location (like https site asking contents from http service)

Use js console in chrome/firefox to debug

Guru
  • 1,303
  • 18
  • 32