Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 部署到heroku时,投票系统不工作_Javascript_Ruby On Rails_Heroku_Voting System - Fatal编程技术网

Javascript 部署到heroku时,投票系统不工作

Javascript 部署到heroku时,投票系统不工作,javascript,ruby-on-rails,heroku,voting-system,Javascript,Ruby On Rails,Heroku,Voting System,我有一个“目的地”列表。每个目的地旁边都有一个LIKE按钮以及LIKE计数。我能够让这个“喜欢系统”在本地运行。但是,一旦部署到heroku,“like count”将显示为“undefined”,然后每当您单击like按钮时,like count将变为“NaN”。如何让liking系统在我的heroku应用程序上运行 在我的javscript控制台中,我注意到没有应该有的like_count列。但我的迁移和模式文件却不这么说 Schmea.rb文件: create_table "destina

我有一个“目的地”列表。每个目的地旁边都有一个LIKE按钮以及LIKE计数。我能够让这个“喜欢系统”在本地运行。但是,一旦部署到heroku,“like count”将显示为“undefined”,然后每当您单击like按钮时,like count将变为“NaN”。如何让liking系统在我的heroku应用程序上运行

在我的javscript控制台中,我注意到没有应该有的like_count列。但我的迁移和模式文件却不这么说

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"
结束

我在一个脚本文件中实现了liking系统:

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;
    }
var-like_cell=row.insertCell(2);

比如_cell.innerHTML='可能会发生这样的事情 1.JS文件正在加载并且没有错误吗? 2.ajax正在调用正确的url。(很有可能它正在调用localhost,正如您所说,它正在本地运行) 3.ajax请求是否需要很长时间?(heroku在30秒内超时) 4.是否存在跨浏览器问题?这就像试图从其他站点和非安全位置加载内容(如https站点从http服务请求内容)


使用chrome/firefox中的js控制台调试

是否加载了Javascript文件?是的。见我的编辑上面。我的数据库文件有问题吗?请转到“网络”选项卡,查看服务器返回的内容。并修复输入标记中的代码。请参阅上面的“我的编辑”。你认为这与我的数据库/迁移有关吗?