使用数据类型为整数的 Ruby On Rails 脚手架时出现错误

发布于 2024-10-09 09:33:02 字数 716 浏览 0 评论 0原文

我正在学习 Ruby On Rails。我使用 Ruby 版本 1.8.1 和 Rails 版本 2.3.10 的共享主机。我正在学习 http://railstutorial.org/ 上的教程Chapters/a-demo-app?version=2.3#top 在教程中的某个时刻它让我运行:

script/generate scaffold Micropost content:string user_id:interger

本教程使用默认数据库 SQLite3。该命令有效,我使用 rake db:migrate 创建数据库。我可以查看列出微帖子的页面(该页面为空),但是当我尝试添加微帖子(微帖子/新)时,出现错误 undefined method `user_id' for #在我自己做了一些测试之后,我似乎在使用interger数据类型时遇到了这个问题。

虽然我知道使用脚手架并不是在 Rails 上构建 ruby​​ 的最佳方法,但我才刚刚开始,仍然想知道为什么我会遇到这个问题,以帮助我更好地理解 Rails 的工作原理。

I am learning Ruby On Rails. I am on a shared hosting with Ruby version 1.8.1 and Rails version 2.3.10. I am working my way through a tutorial at http://railstutorial.org/chapters/a-demo-app?version=2.3#top and at one point in the tutorial it has me run:

script/generate scaffold Micropost content:string user_id:interger

The tutorial is using the default database, SQLite3. The command works and I use rake db:migrate to create the database. I can view the page listing the microposts (which is empty), but when I try to add a micropost (microposts/new) I get an error undefined method `user_id' for #<Micropost:0x7f710e4988e8> After doing some testing on my own it seems I experience the problem by using the data type of interger.

While I understand that using a scaffold is not the best way of building a ruby on rails, I'm just beginning and would still like to know why I am experiencing this problem to help me better understand how rails works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

清泪尽 2024-10-16 09:33:02

您是否将 integer 输入为 interger

Have you mistyped integer as interger?

初相遇 2024-10-16 09:33:02

在这个问题中,您似乎将整数拼写错误了三遍,所以我猜您在代码中也写错了。正确的拼写是整数

You seem to have spelled integer wrong three times in this question, so I would guess that you got it wrong in the code too. The correct spelling is integer.

小伙你站住 2024-10-16 09:33:02

你应该经常检查是否有拼写错误。您的微博表是否有“user_id”列
你可以在迁移文件中查找它

you should always check for typos. does your table for Microposts have the column 'user_id'
you can look it up in the migration file

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