使用数据类型为整数的 Ruby On Rails 脚手架时出现错误
我正在学习 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 #
虽然我知道使用脚手架并不是在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否将
integer
输入为interger
?Have you mistyped
integer
asinterger
?在这个问题中,您似乎将整数拼写错误了三遍,所以我猜您在代码中也写错了。正确的拼写是整数。
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.
你应该经常检查是否有拼写错误。您的微博表是否有“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