I've seen this error while working on nested routes. It occurred when the controller routes are defined as nested under another controller's route.
For example:
resources :authors do
resource :books, only: [index, :new]
end
it will create following routes:
/authors/author_id/books/:id
/authors/author_id/books/new
The method form_with try to execute the method book_path. But it is defined as author_books_path.
I found the solution by adding extra resources :books outside of the resources :books block.
resources :books
resources :authors do
resource :books, only: [:index, :new]
end
Edit:
This solution will build the form without error but action URL won't be be correct because it will use books/.. instead of author/:author_id/books. That's why it is better use form_for instead of form_with while working on nested routes by passing parent and child model in a array.
<% form_for [@author, @book] do |form| %>