开发者

ActionView errors when pushing to Heroku

I'm building my first webapp, following the Michael Hartl Rails Tutorial. After finishing Chapter 10, I find that my application works locally but 开发者_如何学JAVAdoes not work when I push it to Heroku. The development log output reads:

Started GET "/" for 98.154.183.51 at Thu Jan 06 01:07:15 -0800 2011
  Processing by PagesController#home as HTML
Rendered layouts/_header.html.erb (28.3ms)
Rendered pages/home.html.erb within layouts/application (30.9ms)
Completed   in 35ms
 User Load (29.6ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 101) LIMIT 1
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 101) LIMIT 1
Rendered layouts/_header.html.erb (149.3ms)
  CACHE (0.0ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 101) LIMIT 1
Rendered layouts/_sidebar.html.erb (8.1ms)
Rendered layouts/_footer.html.erb (0.6ms)
Rendered sessions/new.html.erb within layouts/application (342.4ms)
Completed 200 OK in 421ms (Views: 390.1ms | ActiveRecord: 29.9ms)

Whereas the heroku production log reads:

Started GET "/" for 98.154.183.51 at Thu Jan 06 01:07:15 -0800 2011
  Processing by PagesController#home as HTML
Rendered layouts/_header.html.erb (28.3ms)
Rendered pages/home.html.erb within layouts/application (30.9ms)
Completed   in 35ms

ActionView::Template::Error (PGError: ERROR:  invalid input syntax for integer: "nil"
: SELECT "users".* FROM "users" WHERE ("users"."id" = 'nil') LIMIT 1):

I'm not sure why the Heroku-deployed app looks for a user_id of "nil", whereas my local app looks for one of "101." This is my first app, so I'm not sure where to even begin the troubleshooting. I've tried pushing my local db to the Heroku one via heroku rake db:push, but I still get the same errors. Any advice? Thanks in advance for your help.


Make sure you

  1. Migrated your database on Heroku with heroku rake db:migrate
  2. Have a valid user in your database (you could e.g. create one with the Rails console on Heroku)

It seems your code is trying to load a User instance when you have none in your database. If your app works once you have some users in your database, fix your code to act appropriately if no users are present.


You might want to run you rake db:seed also if you have setup some initial values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜