2012-10-21 251 views
1

這個問題已被問了很多,但仍然沒有任何工作似乎。我的應用程序在測試中運行良好,但在heroku上運行時,出現錯誤500,表示「我們很抱歉,但出錯了。」我檢查了服務器的日誌文件,我的錯誤,似乎什麼地方在這裏: ActiveRecord :: StatementInvalid error

2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: Started GET "/" for 117.192.23.223 at 2012-10-21 15:29:40 +0000 
2012-10-21T15:29:40+00:00 app[web.1]: cache: [GET /] miss 
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 heroku[router]: GET whispering-coast-7415.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=5ms status=301 bytes=115 
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: Started GET "/movies" for 117.192.23.223 at 2012-10-21 15:29:40 +0000 
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: Processing by MoviesController#index as HTML 
2012-10-21T15:29:40+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms 
2012-10-21T15:29:40+00:00 heroku[router]: GET whispering-coast-7415.herokuapp.com/movies dyno=web.1 queue=0 wait=0ms service=17ms status=500 bytes=728 
2012-10-21T15:29:40+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR: column "movies.id" must appear in the GROUP BY clause or be used in an aggregate function 
2012-10-21T15:29:40+00:00 app[web.1]: LINE 1: SELECT "movies".* FROM "movies" GROUP BY rating 
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]:    ^
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:40+00:00 app[web.1]: cache: [GET /movies] miss 
2012-10-21T15:29:40+00:00 app[web.1]: : SELECT "movies".* FROM "mo 
vies" GROUP BY rating): 
2012-10-21T15:29:40+00:00 app[web.1]: app/controllers/movies_controller.rb:11:in `index' 
2012-10-21T15:29:40+00:00 app[web.1]: app/models/movie.rb:4:in `get_ratings' 
2012-10-21T15:29:40+00:00 app[web.1]: 
2012-10-21T15:29:41+00:00 heroku[router]: GET whispering-coast-7415.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=8ms status=200 bytes=0 
2012-10-21T15:29:41+00:00 app[web.1]: cache: [GET /favicon.ico] stale, invalid, store 

+0

您可以將MovieController索引操作添加到問題中嗎? – Mab879

回答

0

的PostgreSQL(在Heroku)要求您GROUP BY 所有在這種情況下,SELECT列表中的列,以便代替的:

SELECT "movies".* FROM "movies" GROUP BY rating 

你可能想要做這樣的事情:

SELECT rating FROM "movies" GROUP BY rating 

或Rails的:

Movie.select(:rating).group(:rating) 
相關問題