Christopher Warren on Ruby on Rails, Programming, Photography, and Life
{ 2008 02 28 }
If you’re doing a form post to a nested resource, like creating a comment under /posts/1/comments/ with a route like map.resources :posts do |post| post.resources :comments end you have to account for that when you’re creating a form, you can’t just send it to the comment and hope everything will work out.
/posts/1/comments/
map.resources :posts do |post| post.resources :comments end
It took me a little time to find this, so I’m posting it in hopes of making someone else’s day easier. What I had to do was form_for([@post,@comment]) and now everything is happy again.
form_for([@post,@comment])
schrockwell | 28-Mar-09 at 8:56 pm | Permalink
I made an account just to reply to this and say “thanks” for solving this exact problem for me. This was the second result (after the Rails API) when I searched for “rails nested resources form”.
Perfect.
Christopher | 28-Mar-09 at 10:01 pm | Permalink
That’s fantastic. Thanks for the comment, I’m glad to hear the post helped you out.
You must be logged in to post a comment.
Christopher Warren is a Ruby on Rails developer from Minneapolis, MN.
schrockwell | 28-Mar-09 at 8:56 pm | Permalink
I made an account just to reply to this and say “thanks” for solving this exact problem for me. This was the second result (after the Rails API) when I searched for “rails nested resources form”.
Perfect.
Christopher | 28-Mar-09 at 10:01 pm | Permalink
That’s fantastic. Thanks for the comment, I’m glad to hear the post helped you out.