nested_forms Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh is now part of LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
We all know, Comments are every where Blogs, Social Networking sites, e-learning forums etc. In this article, we've got an Article model and we want to create a nested commenting system onto that. Such that Article can have comments, comments can have replys, replys can have more replys and so on. For example - This is an article This is an comment this is a reply this is a reply's reply .... (so on) This is another comment. Now, we're going to talk about polymorphic associations and what they are and how they can be implemented for nested commenting system. What
Feature is used when you need to save your nested model with the parent model. Use-Case: Suppose you have a model say Person and it can be associated with N number of Contacts. Using nested form we can associate 1..n contacts to the person. Approach: For associating a contact to a person, we need to build the contact model with respect to the person model. For has_many relation, @contact = @person.contacts.build and if has_one relation @contact = @person.build_contact. Now we can use the @contact in the view, for this we use fields_for tag. And