1

I have this routes

resources :childs do
  resources :draws
end
resources :draws

How can I write a single _form.htm.erb for adding and editing draws?

I mean, from new_draw_path I would use form_for(@draw) and then select the child with f.select helper

and from new_child_draw_path I would use form_for([@child,@draw]) selecting child from params

How could I combine both approaches in a single view or helper ?

1 Answers1

0

url_for disregards nils in an array so [@variable_that_is_nil, @draw] is the same as [@draw] or just @draw. so it is fine to use [@child, @draw] in form_for. You just have to add some conditionals inside the form to have a select for a list of children (might be confusing but I'm referring to the list of child ids to select from) if @child is not declared.

jvnill
  • 29,479
  • 4
  • 83
  • 86