# Form fields

**URL:** <https://www.ruby-forum.com/t/form-fields/118442>\
**Category:** Rails\
**Created:** [October 27, 2007, 12:03am UTC](https://www.ruby-forum.com/t/form-fields/118442 "2007-10-27T00:03:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [October 27, 2007, 12:03am UTC](https://www.ruby-forum.com/t/form-fields/118442/1 "2007-10-27T00:03:16Z")

</div>

Hi,

Background:  
I have customer’s details in the customers table (for example email,  
address…)

Whenthat customer proceeds to checkout (which is controlled by the  
cart\_controller not the customer-controller), the checkout form fields  
display empty. For example:

Address

\<%= text\_field :order, :ship\_to\_address %\>

How can I show the customer’s details in the form fields? but still  
use the form input to process the order?

TIA,  
Elle

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [October 27, 2007, 12:30am UTC](https://www.ruby-forum.com/t/form-fields/118442/2 "2007-10-27T00:30:16Z")

</div>

Take a look at form\_for.

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [October 27, 2007, 9:52am UTC](https://www.ruby-forum.com/t/form-fields/118442/3 "2007-10-27T09:52:13Z")

</div>

On 2007-10-26 22:50:47 -0700, elle  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> What if I want details from one model/table to appear in the fields  
> but the final input to go to another model?  
> The relationships are already in place. I’m just not sure how the  
> checkout form can display custotmer’s details (if they exist), so the  
> customer doesn’t have to re-type them all the time.

I think what you’re looking for is text\_field\_tag:

text\_field is tied to a model attribute and uses only its actual value.  
text\_field\_tag lets you set up your own field and load your own value.  
For example:

\<%= text\_field\_tag ‘order[ship\_to\_address]’,  
@order.ship\_to\_address || @customer.address %\>

This will preload the field with the given value from @customer. The ||  
expression is for loading it from an existing order instance if the  
customer has already filled this out.

–Andrew V.

---

<div class="post-metadata">

**Author:** ![elle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ccd318/32.png) [@elle](https://www.ruby-forum.com/u/elle)\
**Post date:** [October 27, 2007, 7:51am UTC](https://www.ruby-forum.com/t/form-fields/118442/4 "2007-10-27T07:51:15Z")

</div>

I’m not sure what you mean. I had a look at form\_for and it looks the  
same, besides the way to lay out your fields. It still sends me to the  
same action.

What if I want details from one model/table to appear in the fields  
but the final input to go to another model?  
The relationships are already in place. I’m just not sure how the  
checkout form can display custotmer’s details (if they exist), so the  
customer doesn’t have to re-type them all the time.

I’m probably missing something. Can form\_for do that?

Elle

On Oct 27, 9:30 am, Gerjan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
