If we've models as:
class Book < ApplicationRecord
has_many :chapters
end
class Chapter < ApplicationRecord
belongs_to :book
end
with routes:
resources :books do
resources :chapters
end
and we want to create a form as:
<%= form_with(url: new_book_chapter_url(chapter) do |f| %>
How could we create this kind of form (/books/:id/chapters/new
) without setting the book
id ?
The example above will throw:
No route matches {:action => "new",
:book_id => nil,
:controller => "chapter"},
missing required keys: [:book_id]
In my case the user set the wished book
within the form, and I'd like it to be blank
when the form appears