How should I use rails and simple_form for nested resources?
Use f.simple_fields_for
instead of simple_fields_for
:
<%= f.simple_fields_for :profile do |p| %> <%= p.input :name %><% end %>
In my case I had the object "book" which belongs to "tour" and "tour" has_many "books".
In the "BookController" in the method "new" I find the tour and initialize the book object:
@tour = Tour.find(params[:tour_id])
@book = Book.new
This is the partial form to create a book: _form.html.erb
<%= simple_form_for [@tour, @book] do |f| %> <%= f.input :name, label: "Name"%> <%= f.input :NoReservations, label: "Number of Reservations" %> <%= f.input :email, label: "Email" %> <h3>Num of available places</h3> <%= f.button :submit %><% end %>