简体   繁体   English

Rails嵌套注释而不使用gem

[英]Rails nested comments without using gems

I am building a simple blog and I do like to implement reddit-like nested replies. 我正在建立一个简单的博客,并且我喜欢实现类似reddit的嵌套回复。 So far I have Posts and Comments. 到目前为止,我有帖子和评论。

I have tried to look for guide or examples but all of the examples are either using gems or are outdated. 我试图寻找指南或示例,但是所有示例都使用了gem或已过时。 Can you suggest me how to approach the problem ? 你能建议我如何解决这个问题吗?

I started with editing routes.rb 我从编辑routes.rb开始

resources :comments do
   resources :comments
end

Comment model: 评论模型:

 has_many :comments

I am not sure how to modify the create function in the controller and how to extend the comments/_form.html 我不确定如何在控制器中修改create函数以及如何扩展comments / _form.html

And what are the remaining steps ? 剩下的步骤是什么?

This is doable via a ccepts_nested_attributes_for . 这可以通过ccepts_nested_attributes_for完成 Check out the documentation on complex forms to get an idea of how to use it. 查看有关复杂表格的文档 ,以了解如何使用它。

I can refer you to a good article on this subject. 我可以推荐您一篇有关此主题的好文章 Well, if you need to ask any questions after reading, just leave a comment. 好吧,如果您需要阅读后问任何问题,只需发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM