我目前在Heroku上有一個應用程序,它一直在拋出這個ActiveRecord查詢中的錯誤。heroku activerecord查詢錯誤
if category == "-1"
where('category_id IS null')
else
where('category_id IS ?', category)
end
與「CATEGORY_ID第一個查詢爲空工作得很好,但第二個查詢拋出這樣的錯誤:
2012-08-16T18:58:03+00:00 app[web.1]:
2012-08-16T18:58:03+00:00 app[web.1]:
2012-08-16T18:58:03+00:00 app[web.1]: Started GET "/items?cpath=4" for 204.154.121.30 at 2012-08-16 18:58:03 +0000
2012-08-16T18:58:08+00:00 app[web.1]:
2012-08-16T18:58:08+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: syntax error at or near "4"
2012-08-16T18:58:08+00:00 app[web.1]: LINE 1: SELECT COUNT(*) FROM "items" WHERE (category_id IS 4)
2012-08-16T18:58:08+00:00 app[web.1]: ^
2012-08-16T18:58:08+00:00 app[web.1]: app/controllers/items_controller.rb:30:in `index'
2012-08-16T18:58:08+00:00 app[web.1]: : SELECT COUNT(*) FROM "items" WHERE (category_id IS 4)):
2012-08-16T18:58:08+00:00 app[web.1]:
2012-08-16T18:58:08+00:00 app[web.1]:
2012-08-16T18:58:08+00:00 app[web.1]: cache: [GET /items?cpath=4] miss
2012-08-16T18:58:08+00:00 app[web.1]: Processing by ItemsController#index as HTML
2012-08-16T18:58:08+00:00 app[web.1]: Parameters: {"cpath"=>"4"}
2012-08-16T18:58:08+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms
2012-08-16T18:58:08+00:00 heroku[router]: GET yisifahan.herokuapp.com/items?cpath=4 dyno=web.1 queue=0 wait=0ms service=
5026ms status=500 bytes=728
2012-08-16T18:58:08+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
2012-08-16T18:58:08+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2012-08-16T18:58:09+00:00 heroku[web.1]: Process exited with status 137
有誰知道如何解決這個問題?謝謝。
所以,對於null語句以及'where where(category:nil)' – Iamvery 2012-08-16 19:17:35
謝謝,這非常有用 – pandapirate 2012-08-16 21:02:08