简体   繁体   中英

Rails nested comments without using gems

I am building a simple blog and I do like to implement reddit-like nested replies. 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. Can you suggest me how to approach the problem ?

I started with editing 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

And what are the remaining steps ?

This is doable via a 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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