R
R
rusrich2018-09-10 19:06:59
Ruby on Rails
rusrich, 2018-09-10 19:06:59

How to set up a form for nested resources in Ruby on Rails 5.2.1 using form_with?

For nested resources in route.rb like

resources :parent, shallow: true do
   resources :child
end

Previously, a form of type form_for was used , where it was possible to specify the names of the parent model first, and then the child :
<%= form_for [@parent, @child] do |form| %>
<%= form_with(model: child, local: true) do |form| %>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oh_shi, 2018-09-11
@rusrich

<%= form_with(model: [@parent, @child], local: true) do |form| %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question