我的应用程序实现了用户可以投票和“取消投票”的“想法”。它在本地运行良好。当推送到 Heroku 时,用户可以投票,但“取消投票”操作不起作用并生成“我们很抱歉,但出了点问题”。来自 herokuapp.com 的页面。
我检查了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]:
我remove_vote
在ideas_controller.rb 中的方法如下:
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
你们中有人有解决这个问题的想法吗?我怀疑这与本地数据库是 SQLite 而 Heroku 上的生产数据库是 PostgreSQL 这一事实有关,但我觉得奇怪的是添加投票有效而删除投票无效。