将 facebook 风格的评论添加到 Rails on Ruby 教程中的微博中
首先,我对 Ruby on Rails 是全新的,并且在编程方面非常生疏。我已经做了一些研究,但我仍在尝试了解 RoR 的基本内部工作原理。我已经完成了 MHartl 的 Ruby on Rails 教程。
我试图扩展我对 Ruby on Rails 的了解,就是在微博中添加评论功能。我尝试简单地在数据库中添加一个评论列,然后将其添加到已经运行的微帖子中。我还尝试使用以下行生成一个名为comments的新模型:
rails generate model Comment content:string user_id:integer micropost_id:integer
我想我可能已经在最后一个模型上做了一些事情,但在实现它时我遇到了障碍。有人可以指出我正确的方向吗?
First and foremost, I am brand new to Ruby on Rails and very rusty when it comes to programming. I have done some research but I am still trying to learn the basic inner workings of RoR. I have completed the Ruby on Rails Tutorial by MHartl.
What I am attempting to do to expand my knowledge of Ruby on Rails is to add a comment function to the Microposts. I have tried to simply add a comment column into the db and then work it into the already functioning microposts. I have also tried to generate a new model called commments using the following line:
rails generate model Comment content:string user_id:integer micropost_id:integer
I think I may have been on to something with that last one but I am hitting a road block when it comes to implementing it. Can someone please point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要研究模型之间的 Rails 关联,这些模型允许您将一条记录与其他记录关联起来。我建议查看以下资源:
您的关闭,我认为通过 Rails 进行查看指南将帮助您快速了解要定义的关系类型。如果您需要更多提示,请询问。
You may want to look into Rails associations between models which allow you to associate one record to others. I would recommend looking over the following resources:
Your close and I think that looking through the Rails Guide will get you up to speed on what types of relations you want to define. If you need more hints just ask.