Mats Stijlaart
Mats Stijlaart

Reputation: 5098

Rails form for creation of model and adding relation to other model

I have two models. Writers and Books.
A writer has many books.
After i have created writers, I want to add books to him or her.
In my /writers/1 path i show the writers information and i have a list of his books.
When adding a book, i navigate to the /books/new path.

When i create the book, i want to create the relation to the writer.

What is the best solution to do this? Should I pass the writer to the books/new path?
Or is there another (better) solution?

Upvotes: 0

Views: 64

Answers (1)

Paul Simpson
Paul Simpson

Reputation: 2514

Assuming all books belong to an author, you're going to want to use nested resources. You can read about nested routes in the Rails Guides.

Upvotes: 2

Related Questions