# Parent Child together in input form

**URL:** <https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450>\
**Category:** Rails\
**Created:** [December 16, 2005, 2:05pm UTC](https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450 "2005-12-16T14:05:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [December 16, 2005, 2:05pm UTC](https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450/1 "2005-12-16T14:05:22Z")

</div>

Hi all,

I understand how rails is supposed to work when dealing with one entity  
input form.

However, when I have a relation between two objects (composition):

Customer(1) --------\> (1)Address

How can you create a inputform where both the properties of a Customer  
and  
Address can be filled in?

Regards,

Harm de Laat

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [December 16, 2005, 2:08pm UTC](https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450/2 "2005-12-16T14:08:39Z")

</div>

Harm

Check the thread  
“managing belongs\_to fields in a form”

I posted this very question a few hours ago.

Alain

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [December 16, 2005, 2:14pm UTC](https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450/3 "2005-12-16T14:14:35Z")

</div>

Harm,

Sorry, I misread your post. Your question is different.

I would simply input the 2 objects independantly in the same form

```
  customer = Customer.new
  address = Address.new

```

, build them separately from their parts, link the address to the  
customer and finally save them both.

Alain

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [December 16, 2005, 2:59pm UTC](https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450/4 "2005-12-16T14:59:22Z")

</div>

Harn,

You can start from the default scaffold code, and simply extend it:  
(caution: untested advice, suggested by a newbie !!)

def new  
@customer = Customer.new  
@address = Address.new  
end

def create  
@address = Address.new(params[:address])  
@customer = Customer.new(params[:customer])  
@customer.address = @address

```
if @address.save && @customer.save
  flash[:notice] = 'Member was successfully created.'
  redirect_to :action => 'list'
else
  render :action => 'new'
end

```

end

For the rhtml, update the view (the \_form.rhtml partial) accordingly.

Alain

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [December 16, 2005, 2:44pm UTC](https://www.ruby-forum.com/t/parent-child-together-in-input-form/50450/5 "2005-12-16T14:44:37Z")

</div>

Thx for the reply!

Do you maybe have an example of this?

How do I do this in de RHTML file?

In JSP i might be able to do something like:

\<input type=“text” name="\<%= \<c:out value="${customer.address.street  
}"/\>

What is the equivalent of the above in RHTML?

Regards,

Harm.
