Showing posts with label has_one. Show all posts
Showing posts with label has_one. Show all posts

Friday, August 22, 2008

map.resources + has_one + form_for = surprise, mofo!

If you've got a route like

map.resources :cars, :has_one => :driver


You're probably expecting to use form_for like this:

form_for([@car, @driver])


That won't work. It'll complain about not being able to find the function, 'car_drivers_path' instead of 'car_driver_path'

Fix:

form_for(@driver, :url => car_driver_path(@car))


Hopefully in Rails 2.1.1 this will be fixed using a different, less crazy syntax:

http://rails.lighthouseapp.com/projects/8994/tickets/461-fixed-polymorphic_url-to-be-able-to-handle-singleton-resources

That is all.