Nested Object Forms

Hi all,

I’m trying to use nested object forms for the signup page of an app to
create the client record as well as the admin user. My problem is
that everything in the fields_for the associated record is not getting
rendered from the view – not the fields, not the html, nothing.

How can I make sure that when the user submits the form that the user
is also submitted???


<% form_for(@client) do |client_form| %>
<%= client_form.text_field :company_name %>

<% client_form.fields_for :users do |user_form| %>

Admin Account
Username: <%= user_form.text_field :login %>

<% end %>

<% end %>

I believe that you are trying to allow multiple administrator accounts
to be added when creating a company.

To do so, you will need multiple fields_for as you cannot just do this
for a collection. Looking at it, it looks like it should give an error
instead of just displaying nothing. Actually I don’t know if you can
use a collection, rails surprises you very often with what it can do
and I bet someone has a solution that can do just that.

Otherwise, the solution depends on what version of rails you are

Rails 2.3

Rails 2.2 and below

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs