推送到 Heroku 时 ActionView 出现错误
我正在按照 Michael Hartl Rails 教程 构建我的第一个 Web 应用程序。完成第10章后,我发现我的应用程序可以在本地运行,但是当我将其推送到 Heroku 时不起作用。开发日志输出显示:
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)
而 Heroku 生产日志显示:
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):
我不确定为什么 Heroku 部署的应用程序会查找“nil”的 user_id,而我的本地应用程序会查找“101”之一。这是我的第一个应用程序,所以我不确定从哪里开始进行故障排除。我尝试通过 heroku rake db:push
将本地数据库推送到 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 does 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您
heroku rake db:migrate
在 Heroku 上迁移了数据库看来您的代码正在尝试加载当数据库中没有用户实例时。如果您的应用程序在数据库中有一些用户后就可以运行,请修复您的代码,以便在没有用户存在时采取适当的操作。
Make sure you
heroku rake db:migrate
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.
如果您设置了一些初始值,您可能还想运行 rake db:seed 。
You might want to run you rake db:seed also if you have setup some initial values.