Topic: Nested Form Builder

I am just not to sure how to build a nested form. I have followed Ryan Railscasts but I am unsure on how to create a new instance in my case.

I have the following models

Customer,
Book Manager, and
Book
In my case a customer has many book_managers, and a book_managers has many books.

The part that confused me his to create a new instance in the single form. I have a description which belongs to book and I have a isVisible who belongs to book_managers

Here what i am thinking but doesn't seem to be working

@customer = Customer.find(params[:id])
@bookmanager = BookManager.new(params[:bookmanager])
@book = Book.new(params[:book])
It doesn't work and not sure how to create the relationship. Any help on it is appreciated!

Re: Nested Form Builder

make sure you have attr_accessible set up properly i.e. booksmanagers_attributes

new customer:

@customer = Customer.build
@bookmanager = @customer.bookmanagers.build
@book = @bookmanager.books.build

for edit you should only find customer (if you have proper form structure with "fields_for")

Last edited by rubytree (2012-08-08 17:46:44)

Re: Nested Form Builder

I am having a similar problem. Is it possible for you to go into a little more detail on the different components to make this nested form work?

Thanks