简体   繁体   English

RoR投票系统在本地工作,但在Heroku上部署时则不行

[英]RoR Voting system working locally but not when deployed on Heroku

My app implements 'ideas' that users can vote on and 'unvote'. 我的应用程序实现了用户可以投票和“未投票”的“想法”。 It works fine locally. 它在当地工作正常。 When pushed to Heroku, users can vote but the 'unvote' action does not work and generates a "We're sorry, but something went wrong." 当推送到Heroku时,用户可以投票,但“未投票”的操作不起作用并产生“我们很抱歉,但出了点问题。” page from herokuapp.com. 来自herokuapp.com的页面。

I've checked the heroku logs and the error is as follows : 我检查了heroku日志,错误如下:

2012-05-25T09:47:18+00:00 app[web.1]: Started POST "/ideas/remove_vote/1/1" for 88.171.195.199 at 2012-05-25 09:47:18 +0000
2012-05-25T09:47:18+00:00 app[web.1]: Processing by IdeasController#remove_vote as HTML
2012-05-25T09:47:18+00:00 app[web.1]:   Parameters: {"authenticity_token"=>"mJ5daJfBhf+823VTg9C1+YSBdqVFTFPuJWiO2cIx6iQ=", "u_id"=>"1", "i_id"=>"1"}
2012-05-25T09:47:18+00:00 app[web.1]: Completed 500 Internal Server Error in 8ms
2012-05-25T09:47:18+00:00 app[web.1]: : DELETE FROM "votes" WHERE "votes"."" = $1):
2012-05-25T09:47:18+00:00 app[web.1]:   app/controllers/ideas_controller.rb:85:in `remove_vote'
2012-05-25T09:47:18+00:00 app[web.1]: 
2012-05-25T09:47:18+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR:  zero-length delimited identifier at or near """"
2012-05-25T09:47:18+00:00 app[web.1]:                                           ^
2012-05-25T09:47:18+00:00 app[web.1]: LINE 1: DELETE FROM "votes" WHERE "votes"."" = $1
2012-05-25T09:47:18+00:00 app[web.1]: 
2012-05-25T09:47:18+00:00 app[web.1]: cache: [POST /ideas/remove_vote/1/1] invalidate, pass
2012-05-25T09:47:18+00:00 app[web.1]: 

My remove_vote method in ideas_controller.rb is the following : 我在ideas_controller.rb中的remove_vote方法如下:

def remove_vote
  @vote = Vote.find_by_user_id_and_idea_id(params[:u_id], params[:i_id])
  @vote.destroy
  redirect_to ideas_path
end

Would any of you have an idea to fix this? 你们中的任何人都有想法解决这个问题吗? I suspect it has something to do with the fact that the local database is SQLite and the production one on Heroku is PostgreSQL but I find it strange that adding a vote works and that removing one does not. 我怀疑它与本地数据库是SQLite并且Heroku上的生产数据库是PostgreSQL这一事实有关,但我发现添加投票有效并且删除一个投票无效。

Take a look at the delete statement being issued in that log: DELETE FROM "votes" WHERE "votes"."" = $1 看看在该日志中发出的删除语句: DELETE FROM "votes" WHERE "votes"."" = $1

What column is that where clause talking about? where子句在谈论什么专栏? What column should it be talking about? 它应该谈什么专栏? Is there anything in the Vote model that explains it not using the id column? 投票模型中是否有任何内容可以解释它不使用id列?

When you run into issues like this it is a good idea to configure/run your application locally using postgres. 遇到这样的问题时,最好使用postgres在本地配置/运行应用程序。 This will allow you to debug these issues locally rather than trying to 'guess' what the problem is on Heroku. 这将允许您在本地调试这些问题,而不是试图“猜测”Heroku上的问题。

Here is a good railscast on getting postgres running locally. 这是一个关于让postgres在本地运行的良好轨道广播。

http://railscasts.com/episodes/342-migrating-to-postgresql http://railscasts.com/episodes/342-migrating-to-postgresql

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

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