Hi everyone,
I have followed the tutorial given by Ryan at #196 Nested Model Form Part 1 - RailsCasts and it works great. However it doesn't do what I need and not sure if its a concept issues or I might need to change my models.
The models I have his
- Customer - Book, and - BookManager
Here are the relationship Customer has_many :book_managers accepts_nested_attributes_for :book_managers, allow_destroy: :true BookManager attr_accessible :customer_id, :visible, :books_attributes belongs_to :customer has_many :books accepts_nested_attributes_for :books, allow_destroy: :true Book belongs_to :book_manager attr_accessible :book_manager_id, :description
Here a diagram
-------------|1---------*|-------------|*---------1|-------------| Customer | | BookManager | | Book | -------------| |-------------| |-------------| ID | | ID | | ID | First | | customer_id | | Description | Last | | book_id | |-------------| Email | | isVisible | Password | | isDeleted | -------------| |-------------|
So what I am trying to do is when a customer goes into customer#edit then a form show up. But unlike the tutorial it doesn't create a new customer but a new bookmanager and keep the integrity and also create a new book. That his my problem, not sure how to do it and thank you. Here my customerController and when clicking the button it does say no BookManager controller but not sure how to approach it at the moment.
CustomerController @book_manager = BookManager.new @book_manager.books.build #Need to associate it with customer #Need to generate some control of bookManager because of BookManager.new