Form fields

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

Take a look at form_for.

On 2007-10-26 22:50:47 -0700, elle
[email protected] 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.

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. [email protected]

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