# Nested resources form\_for problem

**URL:** <https://www.ruby-forum.com/t/nested-resources-form-for-problem/124426>\
**Category:** Rails\
**Created:** [December 28, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/nested-resources-form-for-problem/124426 "2007-12-28T16:52:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 28, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/nested-resources-form-for-problem/124426/1 "2007-12-28T16:52:57Z")

</div>

Hi,

I have a resource map like this:

map.resources :users do |user|  
user.resource :sreg10record  
end

So a User is supposed to have (at most) one Sreg10record. The problem  
is in the views. I tried following this tutorial:

> **[Rolling with Rails 2.0 - The First Full Tutorial - Part 1 | AkitaOnRails.com](https://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial)**
>
> for brazilians: click here.
> I am very happy to see that my Rails 2.0 Screencast was very well received. More than 1,500 unique visitors watched it...

which proposes something like:

\<% form\_for( [@user, @sreg10record] ) do |f| %\>

However, doing that yields “undefined method `has\_key?’ for  
#Sreg10record:0xb6f47bc4”. So I tried

\<% form\_for( [:user, @sreg10record] ) do |f| %\>

as intended for namespaced resources, however that causes the ID of  
the record to be used in the URL, which then causes the controller to  
fail when retrieving @user. Experiments with url\_for (which appears to  
be used by form\_for anyway) or user\_sreg10record\_url(@user) failed in  
more or less entertaining ways too. So, how do I make form\_for  
generate a valid path like “/users/\<user\_id\>/sreg10record”?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 28, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/nested-resources-form-for-problem/124426/2 "2007-12-28T17:02:24Z")

</div>

A small addition: when using

\<% form\_for( user\_sreg10record\_url(@user) ) %\>

the generated URL is apparently right, but all form fields are left  
empty. Submitting the form ends up somewhere where “Only get requests  
are allowed.” In the form, there’s a happy mixture of the user’s ID  
and the record’s ID.

On Dec 28, 4:52 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
