简体   繁体   English

部署到heroku时投票系统无法正常工作

[英]voting system not working when deployed to heroku

I have a list of 'destinations'. 我有一个“目的地”列表。 There is a LIKE button next to each destination as well as a like count. 每个目的地旁边都有一个LIKE按钮以及一个类似的计数。 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'. 但是,一旦部署到heroku,“赞计数”将显示为“未定义”,然后每当您单击赞按钮时,赞计数就会变为“ NaN”。 How can I get the liking system to work on my heroku app?? 如何使喜欢的系统在我的heroku应用程序上运行?

In my javscript console, I notice there is no like_count column like there should be. 在我的javscript控制台中,我注意到没有应该有的like_count列。 But my migration and schema file say otherwise... 但是我的迁移和架构文件却说...

Schmea.rb file: Schmea.rb文件:

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: 我在javscript文件中实现了喜欢的系统:

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;
    }

possibility to fell such things 1. Is JS files loading and without error? 发生此类事情的可能性1. JS文件是否已加载且没有错误? 2. Is ajax making call to correct url. 2. ajax正在调用正确的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? (就像您说的那样,它正在向本地主机发出呼叫的机会)3. ajax请求是否需要很长时间? (heroku timeouts in 30 seconds) 4. Any cross browser problem is there? (heroku超时时间为30秒)4.是否存在跨浏览器问题? It is like trying to load contents from other site and from non secure location (like https site asking contents from http service) 这就像试图从其他站点和非安全位置加载内容(例如https站点从http服务询问内容)

Use js console in chrome/firefox to debug 在chrome / firefox中使用js控制台进行调试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM