# Rails 3 beta nested forms

**URL:** <https://www.ruby-forum.com/t/rails-3-beta-nested-forms/189248>\
**Category:** Rails\
**Created:** [May 27, 2010, 1:12pm UTC](https://www.ruby-forum.com/t/rails-3-beta-nested-forms/189248 "2010-05-27T13:12:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AppleII717](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@AppleII717](https://www.ruby-forum.com/u/AppleII717)\
**Post date:** [May 27, 2010, 1:12pm UTC](https://www.ruby-forum.com/t/rails-3-beta-nested-forms/189248/1 "2010-05-27T13:12:49Z")

</div>

Not sure if this the best place to look for rails 3.0 beta 3 help, but  
I’ll give it a try.

I can’t seem to get nested forms to work in the beta - close but no  
workie!

I used an approach similar to one I used in a 2.3 application to  
update a user record from a profile record (citizen has\_one :user,  
accepts\_nested\_attributes\_for :user ) except I’m try to create a user  
record from a has\_many relation (initial registration for a new group/  
subdomain)

class Group \< ActiveRecord::Base  
has\_many :users  
accepts\_nested\_attributes\_for :users, :allow\_destroy =\> true  
end

I have my nested form set up with:

```
<%= f.fields_for :user, @user do |user_fields| %>

```

…

The form builds, but not the same has in 2.3

For instance, in 2.3 I’ll get:

name=“group[user\_attributes][password\_confirmation]”

in 3 I’ll get:

name=“group[user][password\_confirmation]”

submitting the form will generate an error with unknown variable  
“user”

Has anyone gotten nested forms to work in 3?  
Am I missing some new approach that sets [group][user\_attributes]  
instead of [group] [user]?  
Do you have to do something different with a nested has\_many relation?  
(since I assume it would normally be an array)

Steve A.

---

<div class="post-metadata">

**Author:** ![AppleII717](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/59ef9b/32.png) [@AppleII717](https://www.ruby-forum.com/u/AppleII717)\
**Post date:** [May 27, 2010, 2:08pm UTC](https://www.ruby-forum.com/t/rails-3-beta-nested-forms/189248/2 "2010-05-27T14:08:27Z")

</div>

It never fails! If you are having a problem trying to get something to  
work, post something looking for help and within 15 minutes, you’ll  
figure it out!

I went back and reviewed the railscast on nested forms, which used a  
has\_many form and answered my 3rd question = you have to have an  
array.

In my new action in the Groups controller I just added:

```
1.times {@group.users.build}

```

and changed my fields\_for to:

```
<%= f.fields_for :users do |user_fields| %>

```

and everything worked! Singular - plural is something you just always  
have to think of.

Steve
