推送到 Heroku 时 ActionView 出现错误

发布于 2024-10-10 11:09:06 字数 1711 浏览 1 评论 0原文

我正在按照 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

゛清羽墨安 2024-10-17 11:09:06

确保您

  1. 使用 heroku rake db:migrate 在 Heroku 上迁移了数据库
  2. 在您的数据库中有一个有效的用户(例如,您可以使用 Heroku 上的 Rails 控制台创建一个用户)

看来您的代码正在尝试加载当数据库中没有用户实例时。如果您的应用程序在数据库中有一些用户后就可以运行,请修复您的代码,以便在没有用户存在时采取适当的操作。

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.

不及他 2024-10-17 11:09:06

如果您设置了一些初始值,您可能还想运行 rake db:seed 。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文