3

I have a nested route between object1 and object2. When I try to edit an object2 I got an error:

undefined method `object2_path' for #<#Class:0x000000040b2fa8>:0x000000029c8810>.

config/routes.rb

resources :object1 do
  resources :object2
end

view/object2/_form.html.haml:

= simple_form_for [@object1, @object2] do |f|

If I change the view to add a specific url like:

= simple_form_for [@object1, @object2], :url => object1_object2_path, do |f|

then the edit works but new doesn't.

If instead of object1_object2_path as url I set object1_object2s_path (the index path), both views are rendered but edit fails because the form is pointing to the wrong url (that's obvious, is just a part of the tries I did).

Seoman
  • 783
  • 1
  • 7
  • 18

1 Answers1

13

It seems @object1 is nil in this case:

simple_form_for [@object1, @object2] do |f|

So rails attempts to use the object2_path instead of object1_object2_path. Try to check the value of @object1.

Mik
  • 4,117
  • 1
  • 25
  • 32
  • You were absolutely right. For edit action I wasn't setting @object1. BTW I didn't know this rails behavior. Thanks Mikhail. – Seoman May 29 '12 at 23:49