Forum: Ruby on Rails Form Values not Persisting?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
The B. (Guest)
on 2007-02-07 21:39
I'm using the text_field tag to output my form inputs.  In the past this
works perfectly when using model validation.  Here's my problem.. a
3-step checkout process so I'm collecting form data as I go along.  So
after step 1 (billing address), I'm posting the form with a different
hidden "step" input to the same action.

So the "checkout" action handles all three steps similar to the

def checkout
  if ! @params[:step]
    render :action => "checkout_billing"
  elsif @params[:step] == "shipping"
    errors = valid_billing # check the input for required fields
    if errors.size > 0
      render :action => "checkout_billing"
      render :action => "checkout_shipping"
  elsif @params[:step] == "payment"

So I'm on the checkout_billing page, I enter my first name and nothing
else.  It will render checkout_billing again since there are more
required fields.  But the text_field for billing[first_name] isn't
autopopulated with my first name like the text_field helper usually

Any ideas why?
Chris H. (Guest)
on 2007-02-07 23:42
(Received via mailing list)
the text_field tag expects an object to exist so that it can use the
specified attribute as the value for the field

so say i have the following in my 'new.rhtml' view:

text_field :user, :name

i might have in my 'new' action

@user = => "Billy")

when the view renders, the field will contain the value 'Billy'

keeping that in mind, say i submit my form to a 'create' action

def create
  @user =[:user])
    redirect_to :action => :list and return
  render :action => 'new' and return

what happens here is that if there was a missing field in my form for
whatever reason, i want to render the 'new' template and since i
already instantiated @user, it's attributes will populate the form

in your case, you would need a Billing object created to populate your
fields, and it doesn't look like you have that.
The B. (Guest)
on 2007-02-08 00:11
Yeah I poked around looking at my different code when it dawned on me
that I needed to load the previous screen's set of data into an object
so I did that and the default values started showing up.

This topic is locked and can not be replied to.